… | |
… | |
20 | |
20 | |
21 | =cut |
21 | =cut |
22 | |
22 | |
23 | package Coro::Semaphore; |
23 | package Coro::Semaphore; |
24 | |
24 | |
25 | use Coro::Process (); |
25 | use Coro (); |
26 | |
26 | |
27 | $VERSION = 0.01; |
27 | $VERSION = 0.01; |
28 | |
28 | |
29 | =item new [inital count, default zero] |
29 | =item new [inital count, default zero] |
30 | |
30 | |
… | |
… | |
45 | =cut |
45 | =cut |
46 | |
46 | |
47 | sub down { |
47 | sub down { |
48 | my $self = shift; |
48 | my $self = shift; |
49 | while ($self->[0] <= 0) { |
49 | while ($self->[0] <= 0) { |
50 | push @{$self->[1]}, $Coro::Process::current; |
50 | push @{$self->[1]}, $Coro::current; |
51 | Coro::Process::schedule; |
51 | Coro::schedule; |
52 | } |
52 | } |
53 | --$self->[0]; |
53 | --$self->[0]; |
54 | } |
54 | } |
55 | |
55 | |
56 | =item $sem->up |
56 | =item $sem->up |