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

Comparing Coro/Coro.pm (file contents):
Revision 1.40 by root, Sun Oct 28 17:00:05 2001 UTC vs.
Revision 1.41 by root, Tue Nov 6 20:34:09 2001 UTC

38 38
39use Coro::State; 39use Coro::State;
40 40
41use base Exporter; 41use 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
213Create a new process and return it. When the sub returns the process 213Create a new process and return it. When the sub returns the process
214automatically terminates as if C<terminate> with the returned values were 214automatically terminates as if C<terminate> with the returned values were
215called. To start the process you must first put it into the ready queue by 215called. To make the process run you must first put it into the ready queue
216calling the ready method. 216by calling the ready method.
217
218The coderef you submit MUST NOT be a closure that refers to variables
219in an outer scope. This does NOT work. Pass arguments into it instead.
220 217
221=cut 218=cut
222 219
223sub _newcoro { 220sub _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
271Sets the priority of the process. Higher priority processes get run before 268Sets (or gets, if the argument is missing) the priority of the
269process. Higher priority processes get run before lower priority
272lower priority processes. Priorities are smalled signed integer (currently 270processes. Priorities are smalled signed integer (currently -4 .. +3),
273-4 .. +3), that you can refer to using PRIO_xxx constants (use the import 271that you can refer to using PRIO_xxx constants (use the import tag :prio
274tag :prio to get then): 272to 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
305sub nice { 303sub nice {
306 $_[0]{prio} -= $_[1]; 304 $_[0]{prio} -= $_[1];
305}
306
307=item $olddesc = $process->desc($newdesc)
308
309Sets (or gets in case the argument is missing) the description for this
310process. This is just a free-form string you can associate with a process.
311
312=cut
313
314sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines