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

Comparing Coro/Coro.pm (file contents):
Revision 1.8 by root, Sat Jul 14 22:14:21 2001 UTC vs.
Revision 1.9 by root, Sun Jul 15 02:35:52 2001 UTC

26 26
27use Coro::State; 27use Coro::State;
28 28
29use base Exporter; 29use base Exporter;
30 30
31$VERSION = 0.03; 31$VERSION = 0.04;
32 32
33@EXPORT = qw(async yield schedule); 33@EXPORT = qw(async yield schedule);
34@EXPORT_OK = qw($current); 34@EXPORT_OK = qw($current);
35 35
36{ 36{
59 sub INIT { 59 sub INIT {
60 async pop @async while @async; 60 async pop @async while @async;
61 } 61 }
62} 62}
63 63
64my $idle = new Coro sub {
65 &yield while 1;
66};
67
68=item $main 64=item $main
69 65
70This coroutine represents the main program. 66This coroutine represents the main program.
71 67
72=cut 68=cut
73 69
74$main = new Coro; 70our $main = new Coro;
75 71
76=item $current 72=item $current
77 73
78The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course). 74The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course).
79 75
82# maybe some other module used Coro::Specific before... 78# maybe some other module used Coro::Specific before...
83if ($current) { 79if ($current) {
84 $main->{specific} = $current->{specific}; 80 $main->{specific} = $current->{specific};
85} 81}
86 82
87$current = $main; 83our $current = $main;
84
85=item $idle
86
87The coroutine to switch to when no other coroutine is running. The default
88implementation prints "FATAL: deadlock detected" and exits.
89
90=cut
91
92# should be done using priorities :(
93our $idle = new Coro sub {
94 print STDERR "FATAL: deadlock detected\n";
95 exit(51);
96};
88 97
89# we really need priorities... 98# we really need priorities...
90my @ready = (); # the ready queue. hehe, rather broken ;) 99my @ready = (); # the ready queue. hehe, rather broken ;)
91 100
92# static methods. not really. 101# static methods. not really.
118=cut 127=cut
119 128
120my $prev; 129my $prev;
121 130
122sub schedule { 131sub schedule {
132 # should be done using priorities :(
123 ($prev, $current) = ($current, shift @ready); 133 ($prev, $current) = ($current, shift @ready || $idle);
124 Coro::State::transfer($prev, $current); 134 Coro::State::transfer($prev, $current);
125} 135}
126 136
127=item yield 137=item yield
128 138
186 196
187=cut 197=cut
188 198
1891; 1991;
190 200
201=head1 SEE ALSO
202
203L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>,
204L<Coro::Signal>, L<Coro::State>.
205
191=head1 AUTHOR 206=head1 AUTHOR
192 207
193 Marc Lehmann <pcg@goof.com> 208 Marc Lehmann <pcg@goof.com>
194 http://www.goof.com/pcg/marc/ 209 http://www.goof.com/pcg/marc/
195 210

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines