edu.cmu.aura.service.util
Class RWLock
java.lang.Object
|
+--edu.cmu.aura.service.util.RWLock
- public final class RWLock
- extends java.lang.Object
A reader/writer lock. This lock will allow multiple
readers, but only a single writer.
TO DO:
- prevent starvation of writers (will only happen under
severe circumstances, but it should be made impossible)
|
Method Summary |
void |
readLock()
Obtain a read lock. |
void |
release()
Release the lock. |
void |
verifyReadLock()
Verifies that the current thread holds a read lock. |
void |
verifyWriteLock()
Verifies that the current thread holds a write lock. |
void |
writeLock()
Obtain an exclusive write lock. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RWLock
public RWLock()
readLock
public final void readLock()
- Obtain a read lock. If a thread holding the write lock
calls this method it will simply return still holding the
write lock. That is write lock is also implicitly a read
lock, and this method will not downgrade the write lock to
a read lock without an explicit release.
writeLock
public final void writeLock()
- Obtain an exclusive write lock. This method will wait for all
readers to complete before obtaining a write lock.
This method will not upgrade read locks to write locks.
release
public final void release()
- Release the lock. This class tracks what sort of lock
this thread holds, and will relase the appropriate lock.
verifyReadLock
public final void verifyReadLock()
- Verifies that the current thread holds a read lock.
verifyWriteLock
public final void verifyWriteLock()
- Verifies that the current thread holds a write lock.