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

Comparing Coro/Coro.pm (file contents):
Revision 1.225 by root, Wed Nov 19 15:29:57 2008 UTC vs.
Revision 1.226 by root, Wed Nov 19 16:01:32 2008 UTC

149 for @{ delete $self->{_on_destroy} || [] }; 149 for @{ delete $self->{_on_destroy} || [] };
150} 150}
151 151
152# this coroutine is necessary because a coroutine 152# this coroutine is necessary because a coroutine
153# cannot destroy itself. 153# cannot destroy itself.
154my @destroy; 154our @destroy;
155my $manager; 155our $manager;
156 156
157$manager = new Coro sub { 157$manager = new Coro sub {
158 while () { 158 while () {
159 (shift @destroy)->_cancel 159 (shift @destroy)->_cancel
160 while @destroy; 160 while @destroy;
340program calls this function, there will be some one-time resource leak. 340program calls this function, there will be some one-time resource leak.
341 341
342=cut 342=cut
343 343
344sub terminate { 344sub terminate {
345 $current->cancel (@_); 345 $current->{_status} = [@_];
346 push @destroy, $current;
347 $manager->ready;
348 do { &schedule } while 1;
346} 349}
347 350
348sub killall { 351sub killall {
349 for (Coro::State::list) { 352 for (Coro::State::list) {
350 $_->cancel 353 $_->cancel
399 402
400=cut 403=cut
401 404
402sub cancel { 405sub cancel {
403 my $self = shift; 406 my $self = shift;
404 $self->{_status} = [@_];
405 407
406 if ($current == $self) { 408 if ($current == $self) {
407 push @destroy, $self; 409 terminate @_;
408 $manager->ready;
409 &schedule while 1;
410 } else { 410 } else {
411 $self->{_status} = [@_];
411 $self->_cancel; 412 $self->_cancel;
412 } 413 }
413} 414}
414 415
415=item $coroutine->throw ([$scalar]) 416=item $coroutine->throw ([$scalar])

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines