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

Comparing Coro/Coro.pm (file contents):
Revision 1.14 by root, Tue Jul 17 02:21:56 2001 UTC vs.
Revision 1.19 by root, Sat Jul 21 03:44:06 2001 UTC

31 31
32use Coro::State; 32use Coro::State;
33 33
34use base Exporter; 34use 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
75our $main = new Coro; 75our $main = new Coro;
76 76
77=item $current 77=item $current (or as function: current)
78 78
79The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course). 79The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course).
80 80
81=cut 81=cut
82 82
84if ($current) { 84if ($current) {
85 $main->{specific} = $current->{specific}; 85 $main->{specific} = $current->{specific};
86} 86}
87 87
88our $current = $main; 88our $current = $main;
89
90sub current() { $current }
89 91
90=item $idle 92=item $idle
91 93
92The coroutine to switch to when no other coroutine is running. The default 94The coroutine to switch to when no other coroutine is running. The default
93implementation prints "FATAL: deadlock detected" and exits. 95implementation 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#
105our @ready = (); # the ready queue. hehe, rather broken ;) 106my @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
2241; 2251;
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
236L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, 243L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>,
237L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. 244L<Coro::Signal>, L<Coro::State>, L<Coro::Event>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines