… | |
… | |
38 | |
38 | |
39 | use Coro::State; |
39 | use Coro::State; |
40 | |
40 | |
41 | use base Exporter; |
41 | use base Exporter; |
42 | |
42 | |
43 | $VERSION = 0.51; |
43 | $VERSION = 0.52; |
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 | ); |
… | |
… | |
210 | |
210 | |
211 | =item new Coro \&sub [, @args...] |
211 | =item new Coro \&sub [, @args...] |
212 | |
212 | |
213 | Create a new process and return it. When the sub returns the process |
213 | Create a new process and return it. When the sub returns the process |
214 | automatically terminates as if C<terminate> with the returned values were |
214 | automatically terminates as if C<terminate> with the returned values were |
215 | called. To start the process you must first put it into the ready queue by |
215 | called. To make the process run you must first put it into the ready queue |
216 | calling the ready method. |
216 | by calling the ready method. |
217 | |
|
|
218 | The coderef you submit MUST NOT be a closure that refers to variables |
|
|
219 | in an outer scope. This does NOT work. Pass arguments into it instead. |
|
|
220 | |
217 | |
221 | =cut |
218 | =cut |
222 | |
219 | |
223 | sub _newcoro { |
220 | sub _newcoro { |
224 | terminate &{+shift}; |
221 | terminate &{+shift}; |
… | |
… | |
266 | wantarray ? @{$self->{status}} : $self->{status}[0]; |
263 | wantarray ? @{$self->{status}} : $self->{status}[0]; |
267 | } |
264 | } |
268 | |
265 | |
269 | =item $oldprio = $process->prio($newprio) |
266 | =item $oldprio = $process->prio($newprio) |
270 | |
267 | |
271 | Sets the priority of the process. Higher priority processes get run before |
268 | Sets (or gets, if the argument is missing) the priority of the |
|
|
269 | process. Higher priority processes get run before lower priority |
272 | lower priority processes. Priorities are smalled signed integer (currently |
270 | processes. Priorities are smalled signed integer (currently -4 .. +3), |
273 | -4 .. +3), that you can refer to using PRIO_xxx constants (use the import |
271 | that you can refer to using PRIO_xxx constants (use the import tag :prio |
274 | tag :prio to get then): |
272 | to get then): |
275 | |
273 | |
276 | PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN |
274 | PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN |
277 | 3 > 1 > 0 > -1 > -3 > -4 |
275 | 3 > 1 > 0 > -1 > -3 > -4 |
278 | |
276 | |
279 | # set priority to HIGH |
277 | # set priority to HIGH |
… | |
… | |
302 | |
300 | |
303 | =cut |
301 | =cut |
304 | |
302 | |
305 | sub nice { |
303 | sub nice { |
306 | $_[0]{prio} -= $_[1]; |
304 | $_[0]{prio} -= $_[1]; |
|
|
305 | } |
|
|
306 | |
|
|
307 | =item $olddesc = $process->desc($newdesc) |
|
|
308 | |
|
|
309 | Sets (or gets in case the argument is missing) the description for this |
|
|
310 | process. This is just a free-form string you can associate with a process. |
|
|
311 | |
|
|
312 | =cut |
|
|
313 | |
|
|
314 | sub desc { |
|
|
315 | my $old = $_[0]{desc}; |
|
|
316 | $_[0]{desc} = $_[1] if @_ > 1; |
|
|
317 | $old; |
307 | } |
318 | } |
308 | |
319 | |
309 | =back |
320 | =back |
310 | |
321 | |
311 | =cut |
322 | =cut |