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

Comparing Coro/Coro/Signal.pm (file contents):
Revision 1.51 by root, Mon Apr 16 13:26:43 2007 UTC vs.
Revision 1.52 by root, Tue Apr 17 21:02:23 2007 UTC

47=item $s->wait 47=item $s->wait
48 48
49Wait for the signal to occur. Returns immediately if the signal has been 49Wait for the signal to occur. Returns immediately if the signal has been
50sent before. 50sent before.
51 51
52Signals are not reliable, so this function might return 52Signals are not reliable: this function might return spuriously without
53spuriously. Always test for the condition you are waiting on. 53the signal being sent. This means you must always test for the condition
54you are waiting for.
55
56(If this is a real problem for you the situation might be remedied in a
57future version).
54 58
55=item $status = $s->timed_wait ($timeout) 59=item $status = $s->timed_wait ($timeout)
56 60
57Like C<wait>, but returns false if no signal happens within $timeout 61Like C<wait>, but returns false if no signal happens within $timeout
58seconds, otherwise true. 62seconds, otherwise true.
59 63
60See C<wait> for reliability concerns. 64See C<wait> for some reliability concerns.
61 65
62=cut 66=cut
63 67
64sub wait { 68sub wait {
65 while (!$_[0][0]) { 69 unless (delete $_[0][0]) {
66 push @{$_[0][1]}, $Coro::current; 70 push @{$_[0][1]}, $Coro::current;
67 &Coro::schedule; 71 &Coro::schedule;
68 } 72 }
69 $_[0][0] = 0;
70} 73}
71 74
72sub timed_wait { 75sub timed_wait {
73 require Coro::Timer; 76 require Coro::Timer;
74 my $timeout = Coro::Timer::timeout($_[1]); 77 my $timeout = Coro::Timer::timeout($_[1]);
75 78
76 while (!$_[0][0]) { 79 unless (delete $_[0][0]) {
77 push @{$_[0][1]}, $Coro::current; 80 push @{$_[0][1]}, $Coro::current;
78 &Coro::schedule; 81 &Coro::schedule;
79 82
80 return 0 if $timeout; 83 return 0 if $timeout;
81 } 84 }
82
83 $_[0][0] = 0;
84 85
85 1 86 1
86} 87}
87 88
88=item $s->send 89=item $s->send

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines