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

Comparing Coro/Coro/SemaphoreSet.pm (file contents):
Revision 1.7 by root, Tue Nov 6 20:34:11 2001 UTC vs.
Revision 1.8 by root, Tue Nov 27 02:51:03 2001 UTC

50=item $sem->down($id) 50=item $sem->down($id)
51 51
52Decrement the counter, therefore "locking" the named semaphore. This 52Decrement the counter, therefore "locking" the named semaphore. This
53method waits until the semaphore is available if the counter is zero. 53method waits until the semaphore is available if the counter is zero.
54 54
55=item $status = $sem->timed_down($id, $timeout)
56
57Like C<down>, but returns false if semaphore couldn't be acquired within
58$timeout seconds, otherwise true.
59
55=cut 60=cut
56 61
57sub down { 62sub down {
58 my $sem = ($_[0][1]{$_[1]} ||= [$_[0][0]]); 63 my $sem = ($_[0][1]{$_[1]} ||= [$_[0][0]]);
59 while ($sem->[0] <= 0) { 64 while ($sem->[0] <= 0) {
60 push @{$sem->[1]}, $Coro::current; 65 push @{$sem->[1]}, $Coro::current;
61 Coro::schedule; 66 Coro::schedule;
62 } 67 }
63 --$sem->[0]; 68 --$sem->[0];
69}
70
71sub timed_down {
72 require Coro::Timer;
73 my $timeout = Coro::Timer::timeout($_[2]);
74
75 my $sem = ($_[0][1]{$_[1]} ||= [$_[0][0]]);
76 while ($sem->[0] <= 0) {
77 push @{$sem->[1]}, $Coro::current;
78 Coro::schedule;
79 $timeout and return;
80 }
81 --$sem->[0];
82 return 1;
64} 83}
65 84
66=item $sem->up($id) 85=item $sem->up($id)
67 86
68Unlock the semaphore again. 87Unlock the semaphore again.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines