… | |
… | |
41 | |
41 | |
42 | our $idle; # idle handler |
42 | our $idle; # idle handler |
43 | our $main; # main coroutine |
43 | our $main; # main coroutine |
44 | our $current; # current coroutine |
44 | our $current; # current coroutine |
45 | |
45 | |
46 | our $VERSION = '2.5'; |
46 | our $VERSION = '3.0'; |
47 | |
47 | |
48 | our @EXPORT = qw(async cede schedule terminate current); |
48 | our @EXPORT = qw(async cede schedule terminate current); |
49 | our %EXPORT_TAGS = ( |
49 | our %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 | ); |
… | |
… | |
133 | }; |
133 | }; |
134 | |
134 | |
135 | # this coroutine is necessary because a coroutine |
135 | # this coroutine is necessary because a coroutine |
136 | # cannot destroy itself. |
136 | # cannot destroy itself. |
137 | my @destroy; |
137 | my @destroy; |
138 | my $manager; |
|
|
139 | $manager = new Coro sub { |
138 | my $manager; $manager = new Coro sub { |
140 | while () { |
139 | while () { |
141 | # by overwriting the state object with the manager we destroy it |
140 | # by overwriting the state object with the manager we destroy it |
142 | # while still being able to schedule this coroutine (in case it has |
141 | # while still being able to schedule this coroutine (in case it has |
143 | # been readied multiple times. this is harmless since the manager |
142 | # been readied multiple times. this is harmless since the manager |
144 | # can be called as many times as neccessary and will always |
143 | # can be called as many times as neccessary and will always |
… | |
… | |
234 | by calling the ready method. |
233 | by calling the ready method. |
235 | |
234 | |
236 | =cut |
235 | =cut |
237 | |
236 | |
238 | sub _new_coro { |
237 | 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; |
|
|
242 | terminate &{+shift}; |
238 | terminate &{+shift}; |
243 | } |
239 | } |
244 | |
240 | |
245 | sub new { |
241 | sub new { |
246 | my $class = shift; |
242 | my $class = shift; |