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

Comparing Coro/Coro.pm (file contents):
Revision 1.100 by root, Tue Dec 12 13:56:45 2006 UTC vs.
Revision 1.101 by root, Fri Dec 29 08:36:34 2006 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.2'; 55our $VERSION = '3.3';
56 56
57our @EXPORT = qw(async cede schedule terminate current unblock_sub); 57our @EXPORT = qw(async 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);
153 # been readied multiple times. this is harmless since the manager 153 # been readied multiple times. this is harmless since the manager
154 # can be called as many times as neccessary and will always 154 # can be called as many times as neccessary and will always
155 # remove itself from the runqueue 155 # remove itself from the runqueue
156 while (@destroy) { 156 while (@destroy) {
157 my $coro = pop @destroy; 157 my $coro = pop @destroy;
158
158 $coro->{status} ||= []; 159 $coro->{status} ||= [];
160
159 $_->ready for @{delete $coro->{join} || []}; 161 $_->ready for @{(delete $coro->{join} ) || []};
162 $_->(@{$coro->{status}}) for @{(delete $coro->{destroy_cb}) || []};
160 163
161 # the next line destroys the coro state, but keeps the 164 # the next line destroys the coro state, but keeps the
162 # coroutine itself intact (we basically make it a zombie 165 # coroutine itself intact (we basically make it a zombie
163 # coroutine that always runs the manager thread, so it's possible 166 # coroutine that always runs the manager thread, so it's possible
164 # to transfer() to this coroutine). 167 # to transfer() to this coroutine).
313 unless ($self->{status}) { 316 unless ($self->{status}) {
314 push @{$self->{join}}, $current; 317 push @{$self->{join}}, $current;
315 &schedule; 318 &schedule;
316 } 319 }
317 wantarray ? @{$self->{status}} : $self->{status}[0]; 320 wantarray ? @{$self->{status}} : $self->{status}[0];
321}
322
323=item $coroutine->on_destroy (\&cb)
324
325Registers a callback that is called when this coroutine gets destroyed,
326but before it is joined. The callback gets passed the terminate arguments,
327if any.
328
329=cut
330
331sub on_destroy {
332 my ($self, $cb) = @_;
333
334 push @{ $self->{destroy_cb} }, $cb;
318} 335}
319 336
320=item $oldprio = $coroutine->prio ($newprio) 337=item $oldprio = $coroutine->prio ($newprio)
321 338
322Sets (or gets, if the argument is missing) the priority of the 339Sets (or gets, if the argument is missing) the priority of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines