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

Comparing Coro/Coro.pm (file contents):
Revision 1.134 by root, Sat Sep 22 14:42:56 2007 UTC vs.
Revision 1.141 by root, Tue Oct 2 10:38:17 2007 UTC

50 50
51our $idle; # idle handler 51our $idle; # idle handler
52our $main; # main coroutine 52our $main; # main coroutine
53our $current; # current coroutine 53our $current; # current coroutine
54 54
55our $VERSION = '3.7'; 55our $VERSION = '3.8';
56 56
57our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 57our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
58our %EXPORT_TAGS = ( 58our %EXPORT_TAGS = (
59 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 59 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
60); 60);
241 my $cb; 241 my $cb;
242 242
243 while () { 243 while () {
244 eval { 244 eval {
245 while () { 245 while () {
246 $cb = &_pool_1 246 _pool_1 $cb;
247 or return;
248
249 &$cb; 247 &$cb;
250 248 _pool_2 $cb;
251 return if &_pool_2;
252
253 undef $cb;
254 schedule; 249 &schedule;
255 } 250 }
256 }; 251 };
257 252
253 last if $@ eq "\3terminate\2\n";
258 warn $@ if $@; 254 warn $@ if $@;
259 } 255 }
260} 256}
261 257
262sub async_pool(&@) { 258sub async_pool(&@) {
263 # this is also inlined into the unlock_scheduler 259 # this is also inlined into the unlock_scheduler
264 my $coro = (pop @async_pool) || new Coro \&pool_handler;; 260 my $coro = (pop @async_pool) || new Coro \&pool_handler;
265 261
266 $coro->{_invoke} = [@_]; 262 $coro->{_invoke} = [@_];
267 $coro->ready; 263 $coro->ready;
268 264
269 $coro 265 $coro
312 308
313=item terminate [arg...] 309=item terminate [arg...]
314 310
315Terminates the current coroutine with the given status values (see L<cancel>). 311Terminates the current coroutine with the given status values (see L<cancel>).
316 312
313=item killall
314
315Kills/terminates/cancels all coroutines except the currently running
316one. This is useful after a fork, either in the child or the parent, as
317usually only one of them should inherit the running coroutines.
318
317=cut 319=cut
318 320
319sub terminate { 321sub terminate {
320 $current->cancel (@_); 322 $current->cancel (@_);
323}
324
325sub killall {
326 for (Coro::State::list) {
327 $_->cancel
328 if $_ != $current && UNIVERSAL::isa $_, "Coro";
329 }
321} 330}
322 331
323=back 332=back
324 333
325# dynamic methods 334# dynamic methods

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines