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

Comparing Coro/Coro.pm (file contents):
Revision 1.58 by pcg, Fri Feb 13 23:17:41 2004 UTC vs.
Revision 1.59 by pcg, Thu Apr 22 04:14:49 2004 UTC

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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines