ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Signal.pm
Revision: 1.86
Committed: Mon Jul 20 23:46:28 2009 UTC (14 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-5_16
Changes since 1.85: +1 -1 lines
Log Message:
5.16

File Contents

# Content
1 =head1 NAME
2
3 Coro::Signal - thread 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.16;
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 $sem->wait ($callback)
51
52 If you pass a callback argument to C<wait>, it will not wait, but
53 immediately return. The callback will be called under the same conditions
54 as C<wait> without arguments would continue the thrad.
55
56 The callback might wake up any number of threads, but is I<NOT> allowed to
57 block (switch to other threads).
58
59 =item $sig->send
60
61 Send the signal, waking up I<one> waiting process or remember the signal
62 if no process is waiting.
63
64 =item $sig->broadcast
65
66 Send the signal, waking up I<all> waiting process. If no process is
67 waiting the signal is lost.
68
69 =item $sig->awaited
70
71 Return true when the signal is being awaited by some process.
72
73 =cut
74
75 #=item $status = $s->timed_wait ($timeout)
76 #
77 #Like C<wait>, but returns false if no signal happens within $timeout
78 #seconds, otherwise true.
79 #
80 #See C<wait> for some reliability concerns.
81 #
82 #=cut
83
84 #ub timed_wait {
85 # require Coro::Timer;
86 # my $timeout = Coro::Timer::timeout($_[1]);
87 #
88 # unless (delete $_[0][0]) {
89 # push @{$_[0][1]}, $Coro::current;
90 # &Coro::schedule;
91 #
92 # return 0 if $timeout;
93 # }
94 #
95 # 1
96 #
97
98 1;
99
100 =back
101
102 =head1 AUTHOR
103
104 Marc Lehmann <schmorp@schmorp.de>
105 http://home.schmorp.de/
106
107 =cut
108