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

Comparing Coro/Coro.pm (file contents):
Revision 1.83 by root, Fri Nov 24 15:34:33 2006 UTC vs.
Revision 1.88 by root, Sun Nov 26 02:54:55 2006 UTC

41 41
42our $idle; # idle handler 42our $idle; # idle handler
43our $main; # main coroutine 43our $main; # main coroutine
44our $current; # current coroutine 44our $current; # current coroutine
45 45
46our $VERSION = '2.5'; 46our $VERSION = '3.0';
47 47
48our @EXPORT = qw(async cede schedule terminate current); 48our @EXPORT = qw(async cede schedule terminate current);
49our %EXPORT_TAGS = ( 49our %EXPORT_TAGS = (
50 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 50 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
51); 51);
133}; 133};
134 134
135# this coroutine is necessary because a coroutine 135# this coroutine is necessary because a coroutine
136# cannot destroy itself. 136# cannot destroy itself.
137my @destroy; 137my @destroy;
138my $manager;
139$manager = new Coro sub { 138my $manager; $manager = new Coro sub {
140 while () { 139 while () {
141 # by overwriting the state object with the manager we destroy it 140 # by overwriting the state object with the manager we destroy it
142 # while still being able to schedule this coroutine (in case it has 141 # while still being able to schedule this coroutine (in case it has
143 # been readied multiple times. this is harmless since the manager 142 # been readied multiple times. this is harmless since the manager
144 # can be called as many times as neccessary and will always 143 # can be called as many times as neccessary and will always
184 183
185=cut 184=cut
186 185
187sub async(&@) { 186sub async(&@) {
188 my $pid = new Coro @_; 187 my $pid = new Coro @_;
189 $manager->ready; # this ensures that the stack is cloned from the manager
190 $pid->ready; 188 $pid->ready;
191 $pid; 189 $pid
192} 190}
193 191
194=item schedule 192=item schedule
195 193
196Calls the scheduler. Please note that the current process will not be put 194Calls the scheduler. Please note that the current process will not be put
234called. To make the process run you must first put it into the ready queue 232called. To make the process run you must first put it into the ready queue
235by calling the ready method. 233by calling the ready method.
236 234
237=cut 235=cut
238 236
239sub _newcoro { 237sub _new_coro {
240 terminate &{+shift}; 238 terminate &{+shift};
241} 239}
242 240
243sub new { 241sub new {
244 my $class = shift; 242 my $class = shift;
245 243
246 $class->SUPER::new (\&_newcoro, @_) 244 $class->SUPER::new (\&_new_coro, @_)
247} 245}
248 246
249=item $process->ready 247=item $process->ready
250 248
251Put the given process into the ready queue. 249Put the given process into the ready queue.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines