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

Comparing Coro/Coro/Semaphore.pm (file contents):
Revision 1.15 by root, Wed Aug 29 01:32:50 2001 UTC vs.
Revision 1.16 by root, Thu Aug 30 02:58:17 2001 UTC

14 14
15 $sig->up; 15 $sig->up;
16 16
17=head1 DESCRIPTION 17=head1 DESCRIPTION
18 18
19This module implements counted semaphores. You can initialize a mutex 19This module implements counting semaphores. You can initialize a mutex
20with any level of parallel users, that is, you can intialize a sempahore 20with any level of parallel users, that is, you can intialize a sempahore
21that can be C<down>ed more than once until it blocks. There is no owner 21that can be C<down>ed more than once until it blocks. There is no owner
22associated with semaphores, so one coroutine can C<down> it while another 22associated with semaphores, so one coroutine can C<down> it while another
23can C<up> it. 23can C<up> it.
24 24
35 35
36use Coro (); 36use Coro ();
37 37
38$VERSION = 0.45; 38$VERSION = 0.45;
39 39
40=item new [inital count, default one] 40=item new [inital count]
41 41
42Creates a new sempahore object with the given initial lock count. The 42Creates a new sempahore object with the given initial lock count. The
43default lock count is 1, which means it is unlocked by default. Zero (or 43default lock count is 1, which means it is unlocked by default. Zero (or
44negative values) are also allowed, in which case the semaphore is locked 44negative values) are also allowed, in which case the semaphore is locked
45by default. 45by default.
113object is destroyed it automatically calls C<up>. 113object is destroyed it automatically calls C<up>.
114 114
115=cut 115=cut
116 116
117sub guard { 117sub guard {
118 $_[0]->down; 118 &down;
119 # double indirection because bless works on the referenced 119 # double indirection because bless works on the referenced
120 # object, not (only) on the reference itself. 120 # object, not (only) on the reference itself.
121 bless \\$_[0], Coro::Semaphore::Guard::; 121 bless \\$_[0], Coro::Semaphore::Guard::;
122} 122}
123 123
124sub Coro::Semaphore::Guard::DESTROY { 124sub Coro::Semaphore::Guard::DESTROY {
125 ${${$_[0]}}->up; 125 &up(${${$_[0]}});
126} 126}
127 127
1281; 1281;
129 129
130=back 130=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines