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

Comparing Coro/Coro.pm (file contents):
Revision 1.78 by root, Wed Nov 1 01:21:21 2006 UTC vs.
Revision 1.82 by root, Fri Nov 24 13:40:36 2006 UTC

41 41
42our $idle; # idle coroutine 42our $idle; # idle coroutine
43our $main; # main coroutine 43our $main; # main coroutine
44our $current; # current coroutine 44our $current; # current coroutine
45 45
46our $VERSION = '2.1'; 46our $VERSION = '2.5';
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);
141 141
142 # the next line destroys the _coro_state, but keeps the 142 # the next line destroys the _coro_state, but keeps the
143 # process itself intact (we basically make it a zombie 143 # process itself intact (we basically make it a zombie
144 # process that always runs the manager thread, so it's possible 144 # process that always runs the manager thread, so it's possible
145 # to transfer() to this process). 145 # to transfer() to this process).
146 $coro->{_coro_state} = $manager->{_coro_state}; 146 $coro->{_coro_state}->_clone_state_from ($manager->{_coro_state});
147 } 147 }
148 &schedule; 148 &schedule;
149 } 149 }
150}; 150};
151 151
162=item async { ... } [@args...] 162=item async { ... } [@args...]
163 163
164Create a new asynchronous process and return it's process object 164Create a new asynchronous process and return it's process object
165(usually unused). When the sub returns the new process is automatically 165(usually unused). When the sub returns the new process is automatically
166terminated. 166terminated.
167
168When the coroutine dies, the program will exit, just as in the main
169program.
167 170
168 # create a new coroutine that just prints its arguments 171 # create a new coroutine that just prints its arguments
169 async { 172 async {
170 print "@_\n"; 173 print "@_\n";
171 } 1,2,3,4; 174 } 1,2,3,4;
229} 232}
230 233
231sub new { 234sub new {
232 my $class = shift; 235 my $class = shift;
233 bless { 236 bless {
234 _coro_state => (new Coro::State $_[0] && \&_newcoro, @_), 237 _coro_state => (new Coro::State \&_newcoro, @_),
235 }, $class; 238 }, $class;
236} 239}
237 240
238=item $process->ready 241=item $process->ready
239 242
241 244
242=cut 245=cut
243 246
244=item $process->cancel (arg...) 247=item $process->cancel (arg...)
245 248
246Temrinates the given process and makes it return the given arguments as 249Terminates the given process and makes it return the given arguments as
247status (default: the empty list). 250status (default: the empty list).
248 251
249=cut 252=cut
250 253
251sub cancel { 254sub cancel {
271 &schedule; 274 &schedule;
272 } 275 }
273 wantarray ? @{$self->{status}} : $self->{status}[0]; 276 wantarray ? @{$self->{status}} : $self->{status}[0];
274} 277}
275 278
276=item $oldprio = $process->prio($newprio) 279=item $oldprio = $process->prio ($newprio)
277 280
278Sets (or gets, if the argument is missing) the priority of the 281Sets (or gets, if the argument is missing) the priority of the
279process. Higher priority processes get run before lower priority 282process. Higher priority processes get run before lower priority
280processes. Priorities are small signed integers (currently -4 .. +3), 283processes. Priorities are small signed integers (currently -4 .. +3),
281that you can refer to using PRIO_xxx constants (use the import tag :prio 284that you can refer to using PRIO_xxx constants (use the import tag :prio
296process). This is a bug that will be fixed in some future version. 299process). This is a bug that will be fixed in some future version.
297 300
298=cut 301=cut
299 302
300sub prio { 303sub prio {
301 my $old = $_[0]{prio}; 304 shift->{_coro_state}->prio (@_)
302 $_[0]{prio} = $_[1] if @_ > 1;
303 $old;
304} 305}
305 306
306=item $newprio = $process->nice($change) 307=item $newprio = $process->nice ($change)
307 308
308Similar to C<prio>, but subtract the given value from the priority (i.e. 309Similar to C<prio>, but subtract the given value from the priority (i.e.
309higher values mean lower priority, just as in unix). 310higher values mean lower priority, just as in unix).
310 311
311=cut 312=cut
312 313
313sub nice { 314sub nice {
314 $_[0]{prio} -= $_[1]; 315 shift->{_coro_state}->nice (@_)
315} 316}
316 317
317=item $olddesc = $process->desc($newdesc) 318=item $olddesc = $process->desc ($newdesc)
318 319
319Sets (or gets in case the argument is missing) the description for this 320Sets (or gets in case the argument is missing) the description for this
320process. This is just a free-form string you can associate with a process. 321process. This is just a free-form string you can associate with a process.
321 322
322=cut 323=cut

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines