public class AtomicLockingMutexSet extends CObject implements Sync
Locking on a set of mutexes in which waiting *without* locking on any of the mutexes. A lock operation is applied only to a first mutex, and the remaining mutexe are locked with trylock. A failure in one of these, implies that that mutex is putted in the head of the mutex list, and a new attempt is tried (until it succeeds). The advantage of this compound locking module is that waiting (lock operation) is done in the first mutex (hence there is no waiting with a locked mutex), and the mutex list elements are permuted automatically to ensure this compound atomic locking).
The correct algorithm pattern to use AtomicLockingMutexSet objects should use try/finally blocks:
mstx.lock();
try
{
...
}
finally
{
mstx.unlock();
}
This class follows DbC(tm) methodology
(Wikipedia).
Where possible, contracts are implement with native's Java assert.
| Constructor and Description |
|---|
AtomicLockingMutexSet(Mutex[] array)
Constructs a AtomicLockingMutexSet with array elements.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
allDefined(Mutex[] array)
All the elements of the array are reference to objects.
|
SyncState |
getStateAndUnlock()
Get current Sync state, and unlock it (if applicable).
|
void |
lock()
Locks mutex.
|
boolean |
lockIsMine()
Is lock owned by me?
|
MutexCV |
newCV()
Create and return a new condition variable attached to current AtomicLockingMutexSet.
|
void |
recoverState(SyncState state)
Recover Sync state.
|
boolean |
trylock()
Try to lock mutex (without waiting).
|
void |
unlock()
Unlocks mutex.
|
await, await, await, broadcast, interruptWaitingThreads, registerAwaitingThreads, signal, syncronizedLockIsMineequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinterruptWaitingThreads, registerAwaitingThreadspublic AtomicLockingMutexSet(Mutex[] array)
array != null && array.length > 0allDefined(array)array - the arraypublic static boolean allDefined(Mutex[] array)
array != null && array.length > 0array - the arraypublic void lock()
!lockIsMine()lockIsMine()public boolean trylock()
!lockIsMine()result && lockIsMine() || !result && !lockIsMine()public void unlock()
lockIsMine()!lockIsMine()public boolean lockIsMine()
lockIsMine in interface SynclockIsMine in interface SyncCVlockIsMine in class CObjectpublic MutexCV newCV()
public SyncState getStateAndUnlock()
SynclockIsMine()getStateAndUnlock in interface Syncpublic void recoverState(SyncState state) throws ThreadInterruptedException
Syncstate != null && state.obj() == this - my state object required!lockIsMine()recoverState in interface Syncstate - Sync state object (returned by getStateAndUnlock)ThreadInterruptedException