ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.pm
(Generate patch)

Comparing Coro/Coro/State.pm (file contents):
Revision 1.75 by root, Wed Sep 19 21:39:15 2007 UTC vs.
Revision 1.76 by root, Tue Sep 25 01:57:28 2007 UTC

36 36
37=head2 MEMORY CONSUMPTION 37=head2 MEMORY CONSUMPTION
38 38
39A newly created coroutine that has not been used only allocates a 39A newly created coroutine that has not been used only allocates a
40relatively small (a few hundred bytes) structure. Only on the first 40relatively small (a few hundred bytes) structure. Only on the first
41C<transfer> will perl stacks (a few k) and optionally C stack. All this 41C<transfer> will perl allocate stacks (a few kb) and optionally
42is very system-dependent. On my x86_64-pc-linux-gnu system this amounts 42a C stack/coroutine (cctx) for coroutines that recurse through C
43to about 8k per (non-trivial) coroutine. 43functions. All this is very system-dependent. On my x86_64-pc-linux-gnu
44system this amounts to about 8k per (non-trivial) coroutine. You can view
45the actual memory consumption using Coro::Debug.
44 46
45=head2 FUNCTIONS 47=head2 FUNCTIONS
46 48
47=over 4 49=over 4
48 50
159 161
160sub guarded_save { 162sub guarded_save {
161 bless [$_[0], $_[0]->save_also ($_[1])], Coro::State::save_guard:: 163 bless [$_[0], $_[0]->save_also ($_[1])], Coro::State::save_guard::
162} 164}
163 165
166=item $state->has_stack
167
168Returns wether the state currently uses a cctx/C stack. An active state
169always has a cctx, as well as the main program. Other states only use a
170cctx when needed.
171
172=item $bytes = $state->rss
173
174Returns the memory allocated by the coroutine (which includes
175static structures, various perl stacks but NOT local variables,
176arguments or any C stack).
177
178=item $state->call ($coderef)
179
180Try to call the given $coderef in the context of the given state. This
181works even when the state is currently within an XS function, and can
182be very dangerous. You can use it to acquire stack traces etc. (see the
183Coro::Debug module for more details). The coderef MUST NOT EVER transfer
184to another state.
185
186=item $state->eval ($string)
187
188Like C<call>, but eval's the string. Dangerous. Do not
189use. Untested. Unused. Biohazard.
190
164=item $prev->transfer ($next) 191=item $prev->transfer ($next)
165 192
166Save the state of the current subroutine in C<$prev> and switch to the 193Save the state of the current subroutine in C<$prev> and switch to the
167coroutine saved in C<$next>. 194coroutine saved in C<$next>.
168 195
176recursion in your code and moving this into a separate coroutine. 203recursion in your code and moving this into a separate coroutine.
177 204
178=item Coro::State::cctx_idle 205=item Coro::State::cctx_idle
179 206
180Returns the number of allocated but idle (free for reuse) C level 207Returns the number of allocated but idle (free for reuse) C level
181coroutines. As C level coroutines are curretly rarely being deallocated, a 208coroutines. Currently, Coro will limit the number of idle/unused cctxs to
182high number means that you used many C coroutines in the past. 2098.
183 210
184=item Coro::State::cctx_stacksize [$new_stacksize] 211=item Coro::State::cctx_stacksize [$new_stacksize]
185 212
186Returns the current C stack size and optionally sets the new I<minimum> 213Returns the current C stack size and optionally sets the new I<minimum>
187stack size to C<$new_stacksize> I<long>s. Existing stacks will not 214stack size to C<$new_stacksize> I<long>s. Existing stacks will not
189possible. Any Coro::State's that starts to use a stack after this call is 216possible. Any Coro::State's that starts to use a stack after this call is
190guarenteed this minimum size. Please note that Coroutines will only need 217guarenteed this minimum size. Please note that Coroutines will only need
191to use a C-level stack if the interpreter recurses or calls a function in 218to use a C-level stack if the interpreter recurses or calls a function in
192a module that calls back into the interpreter. 219a module that calls back into the interpreter.
193 220
221=item @states = Coro::State::list
222
223Returns a list of all states currently allocated.
224
194=cut 225=cut
195 226
196sub debug_desc { 227sub debug_desc {
197 $_[0]{desc} 228 $_[0]{desc}
198} 229}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines