File Coverage

blib/lib/Coro/Signal.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Coro::Signal - thread signals (binary semaphores)
4              
5             =head1 SYNOPSIS
6              
7             use Coro;
8              
9             my $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 and C calls on the same
25             C without some deep thinking: while it should work as
26             documented, it can easily confuse you :->
27              
28             You don't have to load C manually, it will be loaded
29             automatically when you C and call the C constructor.
30              
31             =over 4
32              
33             =cut
34              
35             package Coro::Signal;
36              
37 2     2   860 use common::sense;
  2         5  
  2         11  
38              
39 2     2   631 use Coro::Semaphore ();
  2         5  
  2         89  
40              
41             our $VERSION = 6.514;
42              
43             =item $sig = new Coro::Signal;
44              
45             Create a new signal.
46              
47             =item $sig->wait
48              
49             Wait for the signal to occur (via either C or C). Returns
50             immediately if the signal has been sent before.
51              
52             =item $sig->wait ($callback)
53              
54             If you pass a callback argument to C, it will not wait, but
55             immediately return. The callback will be called under the same conditions
56             as C without arguments would continue the thrad.
57              
58             The callback might wake up any number of threads, but is I allowed to
59             block (switch to other threads).
60              
61             =item $sig->send
62              
63             Send the signal, waking up I waiting process or remember the signal
64             if no process is waiting.
65              
66             =item $sig->broadcast
67              
68             Send the signal, waking up I waiting process. If no process is
69             waiting the signal is lost.
70              
71             =item $sig->awaited
72              
73             Return true when the signal is being awaited by some process.
74              
75             =cut
76              
77             #=item $status = $s->timed_wait ($timeout)
78             #
79             #Like C, but returns false if no signal happens within $timeout
80             #seconds, otherwise true.
81             #
82             #See C for some reliability concerns.
83             #
84             #=cut
85              
86             #ub timed_wait {
87             # require Coro::Timer;
88             # my $timeout = Coro::Timer::timeout($_[1]);
89             #
90             # unless (delete $_[0][0]) {
91             # push @{$_[0][1]}, $Coro::current;
92             # &Coro::schedule;
93             #
94             # return 0 if $timeout;
95             # }
96             #
97             # 1
98             #
99              
100             1;
101              
102             =back
103              
104             =head1 AUTHOR/SUPPORT/CONTACT
105              
106             Marc A. Lehmann
107             http://software.schmorp.de/pkg/Coro.html
108              
109             =cut
110