calypso.util
Class RWLock
java.lang.Object
|
+--calypso.util.RWLock
- public final class RWLock
- extends java.lang.Object
A "read-write" lock. This lock allows for an arbitrary number of
simultaneous readers. The lock can be upgraded to a write lock in two
ways. First, the lock can be upgraded without guaranteeing invariance
across the transition (in other words, the read lock may need to be
released before the write lock can be acquired). The other form of
upgrade guarantees invariance; however, the upgrade can only be
performed by initially locking the lock using the invariant read lock
enter method. Upgrading the lock in either case involves waiting until
there are no more readers. This implementation gives priority to
upgrades and invariant locks which may lead to reader starvation.
Each thread using the lock may re-enter the lock as many times as
needed. However, attempting to re-enter the lock with the invariant
read lock will fail unless the lock was originally entered that way by
the invoking thread.
Only one thread may enter the invariant read lock at a time; other
threads attempting this will block until the owning thread exits the
lock completely.
Note that the implementation assumes that the user of instances of
this class properly pairs the enters/exits.
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
RWLock
public RWLock()
enterReadLock
public void enterReadLock()
throws java.lang.InterruptedException
exitReadLock
public void exitReadLock()
enterInvariantReadLock
public void enterInvariantReadLock()
throws java.lang.InterruptedException
- Enter the invariant read lock. Only one thread at a time can hold
the invariant read lock. This lock guarantees to upgrade to a write
lock without needing to release the read lock.
exitInvariantReadLock
public void exitInvariantReadLock()
enterWriteLock
public void enterWriteLock()
throws java.lang.InterruptedException
exitWriteLock
public void exitWriteLock()