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.76 by root, Mon Dec 15 18:18:34 2008 UTC vs.
Revision 1.77 by root, Mon Dec 15 19:39:40 2008 UTC

54method waits until the semaphore is available if the counter is zero. 54method waits until the semaphore is available if the counter is zero.
55 55
56=cut 56=cut
57 57
58sub down { 58sub down {
59 # Coro::Semaphore::down increases the refcount, which we check in _may_delete
59 Coro::Semaphore::down ($_[0][1]{$_[1]} ||= Coro::Semaphore::_alloc $_[0][0]); 60 Coro::Semaphore::down ($_[0][1]{$_[1]} ||= Coro::Semaphore::_alloc $_[0][0]);
60} 61}
61 62
62#ub timed_down { 63#ub timed_down {
63# require Coro::Timer; 64# require Coro::Timer;
87# } 88# }
88# 89#
89 90
90=item $semset->up ($id) 91=item $semset->up ($id)
91 92
92Unlock the semaphore again. If the semaphore then reaches the default 93Unlock the semaphore again. If the semaphore reaches the default count for
93count for this set and has no waiters, the space allocated for it will be 94this set and has no waiters, the space allocated for it will be freed.
94freed.
95 95
96=cut 96=cut
97 97
98sub up { 98sub up {
99 my ($self, $id) = @_; 99 my ($self, $id) = @_;
101 my $sem = $self->[1]{$id} ||= Coro::Semaphore::_alloc $self->[0]; 101 my $sem = $self->[1]{$id} ||= Coro::Semaphore::_alloc $self->[0];
102 102
103 Coro::Semaphore::up $sem; 103 Coro::Semaphore::up $sem;
104 104
105 delete $self->[1]{$id} 105 delete $self->[1]{$id}
106 if $self->[0] == Coro::Semaphore::count $sem 106 if _may_delete $sem, $self->[0], 1;
107 and !Coro::Semaphore::waiters $sem;
108} 107}
109 108
110=item $semset->try ($id) 109=item $semset->try ($id)
111 110
112Try to C<down> the semaphore. Returns true when this was possible, 111Try to C<down> the semaphore. Returns true when this was possible,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines