95 |
|
* @spec JSR-166 |
96 |
|
* @revised $Date$ |
97 |
|
* @editor $Author$ |
98 |
+ |
* @author Doug Lea |
99 |
|
* |
100 |
|
*/ |
101 |
|
public class Semaphore implements java.io.Serializable { |
109 |
|
final Condition available; |
110 |
|
long count; |
111 |
|
|
112 |
+ |
/** |
113 |
+ |
* Package-private constructor used by FairSemaphore |
114 |
+ |
* @param permits the initial number of permits available |
115 |
+ |
* @param lock the lock to use |
116 |
+ |
*/ |
117 |
|
Semaphore(long permits, ReentrantLock lock) { |
118 |
|
this.count = permits; |
119 |
|
this.lock = lock; |
162 |
|
public void acquire() throws InterruptedException { |
163 |
|
lock.lockInterruptibly(); |
164 |
|
try { |
165 |
< |
while (count <= 0) available.await(); |
165 |
> |
while (count <= 0) |
166 |
> |
available.await(); |
167 |
|
--count; |
168 |
|
} |
169 |
|
catch (InterruptedException ie) { |
198 |
|
public void acquireUninterruptibly() { |
199 |
|
lock.lock(); |
200 |
|
try { |
201 |
< |
while (count <= 0) available.awaitUninterruptibly(); |
201 |
> |
while (count <= 0) |
202 |
> |
available.awaitUninterruptibly(); |
203 |
|
--count; |
204 |
|
} |
205 |
|
finally { |