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

Comparing Coro/Coro.pm (file contents):
Revision 1.24 by root, Wed Jul 25 04:14:37 2001 UTC vs.
Revision 1.28 by root, Fri Aug 10 21:03:40 2001 UTC

36 36
37use Coro::State; 37use Coro::State;
38 38
39use base Exporter; 39use base Exporter;
40 40
41$VERSION = 0.12; 41$VERSION = 0.13;
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{
47 my @async; 47 my @async;
48 my $init;
48 49
49 # this way of handling attributes simply is NOT scalable ;() 50 # this way of handling attributes simply is NOT scalable ;()
50 sub import { 51 sub import {
51 Coro->export_to_level(1, @_); 52 Coro->export_to_level(1, @_);
52 my $old = *{(caller)[0]."::MODIFY_CODE_ATTRIBUTES"}{CODE}; 53 my $old = *{(caller)[0]."::MODIFY_CODE_ATTRIBUTES"}{CODE};
54 my ($package, $ref) = (shift, shift); 55 my ($package, $ref) = (shift, shift);
55 my @attrs; 56 my @attrs;
56 for (@_) { 57 for (@_) {
57 if ($_ eq "Coro") { 58 if ($_ eq "Coro") {
58 push @async, $ref; 59 push @async, $ref;
60 unless ($init++) {
61 eval q{
62 sub INIT {
63 &async(pop @async) while @async;
64 }
65 };
66 }
59 } else { 67 } else {
60 push @attrs, $_; 68 push @attrs, $_;
61 } 69 }
62 } 70 }
63 return $old ? $old->($package, $ref, @attrs) : @attrs; 71 return $old ? $old->($package, $ref, @attrs) : @attrs;
64 }; 72 };
65 } 73 }
66 74
67 sub INIT {
68 &async(pop @async) while @async;
69 }
70} 75}
71 76
72=item $main 77=item $main
73 78
74This coroutine represents the main program. 79This coroutine represents the main program.
185Future versions of this function will allow result arguments. 190Future versions of this function will allow result arguments.
186 191
187=cut 192=cut
188 193
189sub terminate { 194sub terminate {
190 push @destroy, $current; 195 $current->cancel;
191 $manager->ready;
192 &schedule; 196 &schedule;
193 # NORETURN 197 die; # NORETURN
194} 198}
195 199
196=back 200=back
197 201
198# dynamic methods 202# dynamic methods
231 235
232=cut 236=cut
233 237
234sub ready { 238sub ready {
235 push @ready, $_[0]; 239 push @ready, $_[0];
240}
241
242=item $process->cancel
243
244Like C<terminate>, but terminates the specified process instead.
245
246=cut
247
248sub cancel {
249 push @destroy, $_[0];
250 $manager->ready;
236} 251}
237 252
238=back 253=back
239 254
240=cut 255=cut
256 allow per-thread schedulers, but Coro::State does not yet allow this). 271 allow per-thread schedulers, but Coro::State does not yet allow this).
257 272
258=head1 SEE ALSO 273=head1 SEE ALSO
259 274
260L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, 275L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>,
261L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. 276L<Coro::Signal>, L<Coro::State>, L<Coro::Event>, L<Coro::RWLock>,
277L<Coro::Handle>, L<Coro::Socket>.
262 278
263=head1 AUTHOR 279=head1 AUTHOR
264 280
265 Marc Lehmann <pcg@goof.com> 281 Marc Lehmann <pcg@goof.com>
266 http://www.goof.com/pcg/marc/ 282 http://www.goof.com/pcg/marc/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines