… | |
… | |
184 | |
184 | |
185 | =cut |
185 | =cut |
186 | |
186 | |
187 | sub async(&@) { |
187 | sub async(&@) { |
188 | my $pid = new Coro @_; |
188 | my $pid = new Coro @_; |
189 | $manager->ready; # this ensures that the stack is cloned from the manager |
|
|
190 | $pid->ready; |
189 | $pid->ready; |
191 | $pid; |
190 | $pid |
192 | } |
191 | } |
193 | |
192 | |
194 | =item schedule |
193 | =item schedule |
195 | |
194 | |
196 | Calls the scheduler. Please note that the current process will not be put |
195 | Calls the scheduler. Please note that the current process will not be put |
… | |
… | |
234 | called. To make the process run you must first put it into the ready queue |
233 | called. To make the process run you must first put it into the ready queue |
235 | by calling the ready method. |
234 | by calling the ready method. |
236 | |
235 | |
237 | =cut |
236 | =cut |
238 | |
237 | |
239 | sub _newcoro { |
238 | sub _new_coro { |
|
|
239 | $current->_clear_idle_sp; # set the idle sp on the following cede |
|
|
240 | _set_cede_self; # ensures that cede cede's us first |
|
|
241 | cede; |
240 | terminate &{+shift}; |
242 | terminate &{+shift}; |
241 | } |
243 | } |
242 | |
244 | |
243 | sub new { |
245 | sub new { |
244 | my $class = shift; |
246 | my $class = shift; |
245 | |
247 | |
246 | $class->SUPER::new (\&_newcoro, @_) |
248 | $class->SUPER::new (\&_new_coro, @_) |
247 | } |
249 | } |
248 | |
250 | |
249 | =item $process->ready |
251 | =item $process->ready |
250 | |
252 | |
251 | Put the given process into the ready queue. |
253 | Put the given process into the ready queue. |