public final class FifoMutexLock
extends java.lang.Object
Semaphore
and adds
'mut-ex' behaviour.
The problem with Semaphore is that if you create a new instance with 1 permit (i.e. a mutex) then call release, the number of permits goes up to 2.
Constructor and Description |
---|
FifoMutexLock()
Creates a new instance.
|
FifoMutexLock(boolean b)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Wraps call to
Semaphore.acquire() . |
boolean |
attempt(long ms)
Wraps call to
Semaphore.tryAcquire(long, TimeUnit) . |
boolean |
permitAvailable()
Returns true if the permit is currently avaialable.
|
void |
release()
Calls
release on the underlying lock if a oermit is
available to release, otherwise logs a message indicating that releases
and acquires are not balanced. |
public FifoMutexLock()
Creates a new instance. Initialises underlying FIFOSemaphore
with a single permit.
public FifoMutexLock(boolean b)
Creates a new instance.
b
- if true debug logging will be enabledpublic void acquire() throws java.lang.InterruptedException
Wraps call to Semaphore.acquire()
.
java.lang.InterruptedException
- if the lock is interrupted.Semaphore
public boolean attempt(long ms) throws java.lang.InterruptedException
Wraps call to Semaphore.tryAcquire(long, TimeUnit)
.
ms
- the amount of time in millisecondsjava.lang.InterruptedException
- if the lock is interrupted.Semaphore
public void release()
Calls release
on the underlying lock if a oermit is
available to release, otherwise logs a message indicating that releases
and acquires are not balanced.
public boolean permitAvailable()
Returns true if the permit is currently avaialable.