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

Comparing Coro/Coro.pm (file contents):
Revision 1.84 by root, Sat Nov 25 00:40:26 2006 UTC vs.
Revision 1.87 by root, Sun Nov 26 02:16:19 2006 UTC

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
235by calling the ready method. 233by calling the ready method.
236 234
237=cut 235=cut
238 236
239sub _new_coro { 237sub _new_coro {
240# $current->_clear_idle_sp; # set the idle sp on the following cede
241 _set_cede_self; # ensures that cede cede's us first
242 cede;
243 terminate &{+shift}; 238 terminate &{+shift};
244} 239}
245 240
246sub new { 241sub new {
247 my $class = shift; 242 my $class = shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines