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

Comparing Coro/Coro.pm (file contents):
Revision 1.57 by pcg, Sun Nov 30 22:49:25 2003 UTC vs.
Revision 1.65 by root, Tue Feb 22 19:51:58 2005 UTC

38 38
39use vars qw($idle $main $current); 39use vars qw($idle $main $current);
40 40
41use base Exporter; 41use base Exporter;
42 42
43$VERSION = "0.9"; 43$VERSION = 1.1;
44 44
45@EXPORT = qw(async cede schedule terminate current); 45@EXPORT = qw(async cede schedule terminate current);
46%EXPORT_TAGS = ( 46%EXPORT_TAGS = (
47 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 47 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
48); 48);
130 # remove itself from the runqueue 130 # remove itself from the runqueue
131 while (@destroy) { 131 while (@destroy) {
132 my $coro = pop @destroy; 132 my $coro = pop @destroy;
133 $coro->{status} ||= []; 133 $coro->{status} ||= [];
134 $_->ready for @{delete $coro->{join} || []}; 134 $_->ready for @{delete $coro->{join} || []};
135
136 # the next line destroys the _coro_state, but keeps the
137 # process itself intact (we basically make it a zombie
138 # process that always runs the manager thread, so it's possible
139 # to transfer() to this process).
135 $coro->{_coro_state} = $manager->{_coro_state}; 140 $coro->{_coro_state} = $manager->{_coro_state};
136 } 141 }
137 &schedule; 142 &schedule;
138 } 143 }
139}; 144};
184 189
185=cut 190=cut
186 191
187=item terminate [arg...] 192=item terminate [arg...]
188 193
189Terminates the current process. 194Terminates the current process with the given status values (see L<cancel>).
190
191Future versions of this function will allow result arguments.
192 195
193=cut 196=cut
194 197
195sub terminate { 198sub terminate {
196 $current->{status} = [@_];
197 $current->cancel; 199 $current->cancel (@_);
198 &schedule;
199 die; # NORETURN
200} 200}
201 201
202=back 202=back
203 203
204# dynamic methods 204# dynamic methods
233 233
234Put the given process into the ready queue. 234Put the given process into the ready queue.
235 235
236=cut 236=cut
237 237
238=item $process->cancel 238=item $process->cancel (arg...)
239 239
240Like C<terminate>, but terminates the specified process instead. 240Temrinates the given process and makes it return the given arguments as
241status (default: the empty list).
241 242
242=cut 243=cut
243 244
244sub cancel { 245sub cancel {
246 my $self = shift;
247 $self->{status} = [@_];
245 push @destroy, $_[0]; 248 push @destroy, $self;
246 $manager->ready; 249 $manager->ready;
247 &schedule if $current == $_[0]; 250 &schedule if $current == $self;
248} 251}
249 252
250=item $process->join 253=item $process->join
251 254
252Wait until the coroutine terminates and return any values given to the 255Wait until the coroutine terminates and return any values given to the
253C<terminate> function. C<join> can be called multiple times from multiple 256C<terminate> or C<cancel> functions. C<join> can be called multiple times
254processes. 257from multiple processes.
255 258
256=cut 259=cut
257 260
258sub join { 261sub join {
259 my $self = shift; 262 my $self = shift;
336 339
337=head1 SEE ALSO 340=head1 SEE ALSO
338 341
339L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, 342L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>,
340L<Coro::Signal>, L<Coro::State>, L<Coro::Timer>, L<Coro::Event>, 343L<Coro::Signal>, L<Coro::State>, L<Coro::Timer>, L<Coro::Event>,
341L<Coro::L<Coro::RWLock>, Handle>, L<Coro::Socket>. 344L<Coro::Handle>, L<Coro::RWLock>, L<Coro::Socket>.
342 345
343=head1 AUTHOR 346=head1 AUTHOR
344 347
345 Marc Lehmann <pcg@goof.com> 348 Marc Lehmann <pcg@goof.com>
346 http://www.goof.com/pcg/marc/ 349 http://home.schmorp.de/
347 350
348=cut 351=cut
349 352

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines