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.27 by root, Sat Jul 28 01:41:57 2001 UTC vs.
Revision 1.30 by root, Sat Aug 11 19:59:19 2001 UTC

36 36
37use Coro::State; 37use Coro::State;
38 38
39use base Exporter; 39use base Exporter;
40 40
41$VERSION = 0.13; 41$VERSION = 0.45;
42 42
43@EXPORT = qw(async cede schedule terminate current); 43@EXPORT = qw(async cede schedule terminate current);
44@EXPORT_OK = qw($current); 44@EXPORT_OK = qw($current);
45 45
46{ 46{
118 delete ((pop @destroy)->{_coro_state}) while @destroy; 118 delete ((pop @destroy)->{_coro_state}) while @destroy;
119 &schedule; 119 &schedule;
120 } 120 }
121}; 121};
122 122
123# we really need priorities...
124my @ready; # the ready queue. hehe, rather broken ;)
125
126# static methods. not really. 123# static methods. not really.
127 124
128=head2 STATIC METHODS 125=head2 STATIC METHODS
129 126
130Static methods are actually functions that operate on the current process only. 127Static methods are actually functions that operate on the current process only.
160into the ready queue, so calling this function usually means you will 157into the ready queue, so calling this function usually means you will
161never be called again. 158never be called again.
162 159
163=cut 160=cut
164 161
165my $prev;
166
167sub schedule {
168 # should be done using priorities :(
169 ($prev, $current) = ($current, shift @ready || $idle);
170 Coro::State::transfer($prev, $current);
171}
172
173=item cede 162=item cede
174 163
175"Cede" to other processes. This function puts the current process into the 164"Cede" to other processes. This function puts the current process into the
176ready queue and calls C<schedule>, which has the effect of giving up the 165ready queue and calls C<schedule>, which has the effect of giving up the
177current "timeslice" to other coroutines of the same or higher priority. 166current "timeslice" to other coroutines of the same or higher priority.
178 167
179=cut 168=cut
180 169
181sub cede { 170=item terminate
171
172Terminates the current process.
173
174Future versions of this function will allow result arguments.
175
176=cut
177
178sub terminate {
182 $current->ready; 179 $current->cancel;
183 &schedule; 180 &schedule;
184}
185
186=item terminate
187
188Terminates the current process.
189
190Future versions of this function will allow result arguments.
191
192=cut
193
194sub terminate {
195 push @destroy, $current;
196 $manager->ready;
197 &schedule;
198 # NORETURN 181 die; # NORETURN
199} 182}
200 183
201=back 184=back
202 185
203# dynamic methods 186# dynamic methods
234 217
235Put the current process into the ready queue. 218Put the current process into the ready queue.
236 219
237=cut 220=cut
238 221
239sub ready { 222=item $process->cancel
223
224Like C<terminate>, but terminates the specified process instead.
225
226=cut
227
228sub cancel {
240 push @ready, $_[0]; 229 push @destroy, $_[0];
230 $manager->ready;
241} 231}
242 232
243=back 233=back
244 234
245=cut 235=cut

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines