BSsync
Class Lock

java.lang.Object
  extended by BSsync.Lock

public class Lock
extends java.lang.Object

A simple non-reentrant mutual exclusion lock. The lock is free upon construction. Each acquire gets the lock, and each release frees it. Releasing a lock that is already free has no effect.

This implementation makes no attempt to provide any fairness or ordering guarantees.

See Also:
Semaphore

Field Summary
protected  boolean inuse
          The lock status
static boolean verbose
          Set this variable to true for debugging output
 
Constructor Summary
Lock()
          Constructor for a mutex lock.
Lock(java.lang.String name)
          Constructor for a mutex lock with a given name.
 
Method Summary
 void lock()
          Acquire the mutex lock.
 Condition newCondition()
          Create and return a new condition variable associated with this lock.
 Condition newCondition(java.lang.String name)
          Create and return a new condition variable associated with this lock.
 void unlock()
          Release the mutex lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

verbose

public static boolean verbose
Set this variable to true for debugging output


inuse

protected boolean inuse
The lock status

Constructor Detail

Lock

public Lock()
Constructor for a mutex lock.


Lock

public Lock(java.lang.String name)
Constructor for a mutex lock with a given name. The name is only used for debugging output.

Parameters:
name - name of the mutex
Method Detail

lock

public void lock()
Acquire the mutex lock. If the mutex is already locked, the calling thread is blocked until the mutex is available.


unlock

public void unlock()
Release the mutex lock.


newCondition

public Condition newCondition()
Create and return a new condition variable associated with this lock. In normal use, the lock should be one that is used for all synchronization of the object using the Condition. Generally, to prevent nested monitor lockouts, this object should not use any native Java synchronized blocks.


newCondition

public Condition newCondition(java.lang.String name)
Create and return a new condition variable associated with this lock. The name is just used for debugging output. In normal use, the lock should be one that is used for all synchronization of the object using the Condition. Generally, to prevent nested monitor lockouts, this object should not use any native Java synchronized blocks.

Parameters:
name - name of the Condition object.