ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Signal.pm
Revision: 1.76
Committed: Mon Nov 24 07:55:28 2008 UTC (15 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-5_1, rel-5_11
Changes since 1.75: +1 -1 lines
Log Message:
5.1

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 This module implements signals/binary semaphores/condition variables
20 (basically all the same thing). You can wait for a signal to occur or send
21 it, in which case it will wake up one waiter, or it can be broadcast,
22 waking up all waiters.
23
24 It is recommended not to mix C<send> and C<broadcast> calls on the same
25 C<Coro::Signal> - it should work as documented, but it can easily confuse
26 you :->
27
28 =over 4
29
30 =cut
31
32 package Coro::Signal;
33
34 use strict qw(vars subs);
35 no warnings;
36
37 use Coro::Semaphore ();
38
39 our $VERSION = 5.1;
40
41 =item $sig = new Coro::Signal;
42
43 Create a new signal.
44
45 =item $sig->wait
46
47 Wait for the signal to occur (via either C<send> or C<broadcast>). Returns
48 immediately if the signal has been sent before.
49
50 =item $sig->send
51
52 Send the signal, waking up I<one> waiting process or remember the signal
53 if no process is waiting.
54
55 =item $sig->broadcast
56
57 Send the signal, waking up I<all> waiting process. If no process is
58 waiting the signal is lost.
59
60 =item $sig->awaited
61
62 Return true when the signal is being awaited by some process.
63
64 =cut
65
66 #=item $status = $s->timed_wait ($timeout)
67 #
68 #Like C<wait>, but returns false if no signal happens within $timeout
69 #seconds, otherwise true.
70 #
71 #See C<wait> for some reliability concerns.
72 #
73 #=cut
74
75 #ub timed_wait {
76 # require Coro::Timer;
77 # my $timeout = Coro::Timer::timeout($_[1]);
78 #
79 # unless (delete $_[0][0]) {
80 # push @{$_[0][1]}, $Coro::current;
81 # &Coro::schedule;
82 #
83 # return 0 if $timeout;
84 # }
85 #
86 # 1
87 #
88
89 1;
90
91 =back
92
93 =head1 BUGS
94
95 This implementation is not currently very robust when the process is woken
96 up by other sources, i.e. C<wait> might return early.
97
98 =head1 AUTHOR
99
100 Marc Lehmann <schmorp@schmorp.de>
101 http://home.schmorp.de/
102
103 =cut
104