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

Comparing cvsroot/Coro/Coro.pm (file contents):
Revision 1.32 by root, Sun Sep 2 01:03:53 2001 UTC vs.
Revision 1.37 by root, Mon Sep 24 02:25:44 2001 UTC

32 32
33=cut 33=cut
34 34
35package Coro; 35package Coro;
36 36
37no warnings qw(uninitialized);
38
37use Coro::State; 39use Coro::State;
38 40
39use base Exporter; 41use base Exporter;
40 42
41$VERSION = 0.49; 43$VERSION = 0.5;
42 44
43@EXPORT = qw(async cede schedule terminate current); 45@EXPORT = qw(async cede schedule terminate current);
44%EXPORT_TAGS = ( 46%EXPORT_TAGS = (
45 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)],
46); 48);
116# this coroutine is necessary because a coroutine 118# this coroutine is necessary because a coroutine
117# cannot destroy itself. 119# cannot destroy itself.
118my @destroy; 120my @destroy;
119my $manager = new Coro sub { 121my $manager = new Coro sub {
120 while() { 122 while() {
121 delete ((pop @destroy)->{_coro_state}) while @destroy; 123 # by overwriting the state object with the manager we destroy it
124 # while still being able to schedule this coroutine (in case it has
125 # been readied multiple times. this is harmless since the manager
126 # can be called as many times as neccessary and will always
127 # remove itself from the runqueue
128 (pop @destroy)->{_coro_state} = $manager->{_coro_state} while @destroy;
122 &schedule; 129 &schedule;
123 } 130 }
124}; 131};
125 132
126# static methods. not really. 133# static methods. not really.
229=cut 236=cut
230 237
231sub cancel { 238sub cancel {
232 push @destroy, $_[0]; 239 push @destroy, $_[0];
233 $manager->ready; 240 $manager->ready;
241 &schedule if $current == $_[0];
234} 242}
235 243
236=item $oldprio = $process->prio($newprio) 244=item $oldprio = $process->prio($newprio)
237 245
238Sets the priority of the process. Higher priority processes get run before 246Sets the priority of the process. Higher priority processes get run before
279 287
2801; 2881;
281 289
282=head1 BUGS/LIMITATIONS 290=head1 BUGS/LIMITATIONS
283 291
284 - could be faster, especially when the core would introduce special 292 - you must make very sure that no coro is still active on global destruction.
285 support for coroutines (like it does for threads). 293 very bad things might happen otherwise (usually segfaults).
286 - there is still a memleak on coroutine termination that I could not
287 identify. Could be as small as a single SV.
288 - this module is not well-tested.
289 - if variables or arguments "disappear" (become undef) or become
290 corrupted please contact the author so he cen iron out the
291 remaining bugs.
292 - this module is not thread-safe. You must only ever use this module from 294 - this module is not thread-safe. You must only ever use this module from
293 the same thread (this requirement might be loosened in the future to 295 the same thread (this requirement might be loosened in the future to
294 allow per-thread schedulers, but Coro::State does not yet allow this). 296 allow per-thread schedulers, but Coro::State does not yet allow this).
295 297
296=head1 SEE ALSO 298=head1 SEE ALSO

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines