ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Signal.pm
Revision: 1.2
Committed: Tue Jul 3 03:48:36 2001 UTC (22 years, 11 months ago) by root
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Coro::Signal - coroutine signals (binary semaphores)
4
5 =head1 SYNOPSIS
6
7 use Coro::Signal;
8
9 $sig = new Coro::Signal;
10
11 $sig->wait; # wait for signal
12
13 # ... some other "thread"
14
15 $sig->send;
16
17 =head1 DESCRIPTION
18
19 =over 4
20
21 =cut
22
23 package Coro::Signal;
24
25 use Coro::Process ();
26
27 $VERSION = 0.01;
28
29 sub new {
30 bless [], $_[0];
31 }
32
33 sub wait {
34 my $self = shift;
35 if ($self->[0]) {
36 $self->[0] = 0;
37 } else {
38 push @{$self->[1]}, $Coro::current;
39 Coro::Process::schedule;
40 }
41 }
42
43 sub send {
44 my $self = shift;
45 if (@{$self->[1]}) {
46 (shift @{$self->[1]})->ready;
47 } else {
48 $self->[0] = 1;
49 }
50 }
51
52 sub awaited {
53 !!@{$self->[1]};
54 }
55
56 1;
57
58 =back
59
60 =head1 AUTHOR
61
62 Marc Lehmann <pcg@goof.com>
63 http://www.goof.com/pcg/marc/
64
65 =cut
66