… | |
… | |
31 | |
31 | |
32 | use Coro::State; |
32 | use Coro::State; |
33 | |
33 | |
34 | use base Exporter; |
34 | use base Exporter; |
35 | |
35 | |
36 | $VERSION = 0.05; |
36 | $VERSION = 0.09; |
37 | |
37 | |
38 | @EXPORT = qw(async yield schedule terminate); |
38 | @EXPORT = qw(async yield schedule terminate current); |
39 | @EXPORT_OK = qw($current); |
39 | @EXPORT_OK = qw($current); |
40 | |
40 | |
41 | { |
41 | { |
42 | use subs 'async'; |
42 | use subs 'async'; |
43 | |
43 | |
… | |
… | |
52 | my @attrs; |
52 | my @attrs; |
53 | for (@_) { |
53 | for (@_) { |
54 | if ($_ eq "Coro") { |
54 | if ($_ eq "Coro") { |
55 | push @async, $ref; |
55 | push @async, $ref; |
56 | } else { |
56 | } else { |
57 | push @attrs, @_; |
57 | push @attrs, $_; |
58 | } |
58 | } |
59 | } |
59 | } |
60 | return $old ? $old->($package, $name, @attrs) : @attrs; |
60 | return $old ? $old->($package, $ref, @attrs) : @attrs; |
61 | }; |
61 | }; |
62 | } |
62 | } |
63 | |
63 | |
64 | sub INIT { |
64 | sub INIT { |
65 | async pop @async while @async; |
65 | async pop @async while @async; |
… | |
… | |
72 | |
72 | |
73 | =cut |
73 | =cut |
74 | |
74 | |
75 | our $main = new Coro; |
75 | our $main = new Coro; |
76 | |
76 | |
77 | =item $current |
77 | =item $current (or as function: current) |
78 | |
78 | |
79 | The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course). |
79 | The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course). |
80 | |
80 | |
81 | =cut |
81 | =cut |
82 | |
82 | |
… | |
… | |
84 | if ($current) { |
84 | if ($current) { |
85 | $main->{specific} = $current->{specific}; |
85 | $main->{specific} = $current->{specific}; |
86 | } |
86 | } |
87 | |
87 | |
88 | our $current = $main; |
88 | our $current = $main; |
|
|
89 | |
|
|
90 | sub current() { $current } |
89 | |
91 | |
90 | =item $idle |
92 | =item $idle |
91 | |
93 | |
92 | The coroutine to switch to when no other coroutine is running. The default |
94 | The coroutine to switch to when no other coroutine is running. The default |
93 | implementation prints "FATAL: deadlock detected" and exits. |
95 | implementation prints "FATAL: deadlock detected" and exits. |
… | |
… | |
99 | print STDERR "FATAL: deadlock detected\n"; |
101 | print STDERR "FATAL: deadlock detected\n"; |
100 | exit(51); |
102 | exit(51); |
101 | }; |
103 | }; |
102 | |
104 | |
103 | # we really need priorities... |
105 | # we really need priorities... |
104 | ## my @ready; #d# |
|
|
105 | our @ready = (); # the ready queue. hehe, rather broken ;) |
106 | my @ready; # the ready queue. hehe, rather broken ;) |
106 | |
107 | |
107 | # static methods. not really. |
108 | # static methods. not really. |
108 | |
109 | |
109 | =head2 STATIC METHODS |
110 | =head2 STATIC METHODS |
110 | |
111 | |
… | |
… | |
221 | |
222 | |
222 | =cut |
223 | =cut |
223 | |
224 | |
224 | 1; |
225 | 1; |
225 | |
226 | |
226 | =head1 BUGS |
227 | =head1 BUGS/LIMITATIONS |
227 | |
228 | |
228 | - could be faster, especially when the core would introduce special |
229 | - could be faster, especially when the core would introduce special |
229 | support for coroutines (like it does for threads). |
230 | support for coroutines (like it does for threads). |
230 | - there is still a memleak on coroutine termination that I could not |
231 | - there is still a memleak on coroutine termination that I could not |
231 | identify. Could be as small as a single SV. |
232 | identify. Could be as small as a single SV. |
232 | - this module is not well-tested. |
233 | - this module is not well-tested. |
|
|
234 | - if variables or arguments "disappear" (become undef) or become |
|
|
235 | corrupted please contact the author so he cen iron out the |
|
|
236 | remaining bugs. |
|
|
237 | - this module is not thread-safe. You must only ever use this module from |
|
|
238 | the same thread (this requirement might be loosened in the future to |
|
|
239 | allow per-thread schedulers, but Coro::Satte does not yet allow this). |
233 | |
240 | |
234 | =head1 SEE ALSO |
241 | =head1 SEE ALSO |
235 | |
242 | |
236 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
243 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
237 | L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. |
244 | L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. |