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

Comparing Coro/Coro.pm (file contents):
Revision 1.36 by root, Mon Sep 24 01:36:20 2001 UTC vs.
Revision 1.39 by root, Tue Oct 9 00:39:08 2001 UTC

38 38
39use Coro::State; 39use Coro::State;
40 40
41use base Exporter; 41use base Exporter;
42 42
43$VERSION = 0.5; 43$VERSION = 0.51;
44 44
45@EXPORT = qw(async cede schedule terminate current); 45@EXPORT = qw(async cede schedule terminate current);
46%EXPORT_TAGS = ( 46%EXPORT_TAGS = (
47 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 47 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
48); 48);
116}; 116};
117 117
118# this coroutine is necessary because a coroutine 118# this coroutine is necessary because a coroutine
119# cannot destroy itself. 119# cannot destroy itself.
120my @destroy; 120my @destroy;
121my $manager;
121my $manager = new Coro sub { 122$manager = new Coro sub {
122 while() { 123 while() {
123 delete ((pop @destroy)->{_coro_state}) while @destroy; 124 # by overwriting the state object with the manager we destroy it
125 # while still being able to schedule this coroutine (in case it has
126 # been readied multiple times. this is harmless since the manager
127 # can be called as many times as neccessary and will always
128 # remove itself from the runqueue
129 (pop @destroy)->{_coro_state} = $manager->{_coro_state} while @destroy;
124 &schedule; 130 &schedule;
125 } 131 }
126}; 132};
127 133
128# static methods. not really. 134# static methods. not really.
218 }, $class; 224 }, $class;
219} 225}
220 226
221=item $process->ready 227=item $process->ready
222 228
223Put the current process into the ready queue. 229Put the given process into the ready queue.
224 230
225=cut 231=cut
226 232
227=item $process->cancel 233=item $process->cancel
228 234

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines