EDU.oswego.cs.dl.util.concurrent

Class WriterPreferenceReadWriteLock

public class WriterPreferenceReadWriteLock extends Object implements ReadWriteLock

A ReadWriteLock that prefers waiting writers over waiting readers when there is contention. This class is adapted from the versions described in CPJ, improving on the ones there a bit by segregating reader and writer wait queues, which is typically more efficient.

The locks are NOT reentrant. In particular, even though it may appear to usually work OK, a thread holding a read lock should not attempt to re-acquire it. Doing so risks lockouts when there are also waiting writers.

[ Introduction to this package. ]

Nested Class Summary
protected classWriterPreferenceReadWriteLock.ReaderLock
protected abstract classWriterPreferenceReadWriteLock.Signaller
Reader and Writer requests are maintained in two different wait sets, by two different objects.
protected classWriterPreferenceReadWriteLock.WriterLock
Field Summary
protected longactiveReaders_
protected ThreadactiveWriter_
protected WriterPreferenceReadWriteLock.ReaderLockreaderLock_
protected longwaitingReaders_
protected longwaitingWriters_
protected WriterPreferenceReadWriteLock.WriterLockwriterLock_
Method Summary
protected booleanallowReader()
Override this method to change to reader preference *
protected voidcancelledWaitingReader()
protected voidcancelledWaitingWriter()
protected WriterPreferenceReadWriteLock.SignallerendRead()
Called upon termination of a read.
protected WriterPreferenceReadWriteLock.SignallerendWrite()
Called upon termination of a write.
SyncreadLock()
protected booleanstartRead()
protected booleanstartReadFromNewReader()
protected booleanstartReadFromWaitingReader()
protected booleanstartWrite()
protected booleanstartWriteFromNewWriter()
protected booleanstartWriteFromWaitingWriter()
SyncwriteLock()

Field Detail

activeReaders_

protected long activeReaders_

activeWriter_

protected Thread activeWriter_

readerLock_

protected final WriterPreferenceReadWriteLock.ReaderLock readerLock_

waitingReaders_

protected long waitingReaders_

waitingWriters_

protected long waitingWriters_

writerLock_

protected final WriterPreferenceReadWriteLock.WriterLock writerLock_

Method Detail

allowReader

protected boolean allowReader()
Override this method to change to reader preference *

cancelledWaitingReader

protected void cancelledWaitingReader()

cancelledWaitingWriter

protected void cancelledWaitingWriter()

endRead

protected WriterPreferenceReadWriteLock.Signaller endRead()
Called upon termination of a read. Returns the object to signal to wake up a waiter, or null if no such

endWrite

protected WriterPreferenceReadWriteLock.Signaller endWrite()
Called upon termination of a write. Returns the object to signal to wake up a waiter, or null if no such

readLock

public Sync readLock()

startRead

protected boolean startRead()

startReadFromNewReader

protected boolean startReadFromNewReader()

startReadFromWaitingReader

protected boolean startReadFromWaitingReader()

startWrite

protected boolean startWrite()

startWriteFromNewWriter

protected boolean startWriteFromNewWriter()

startWriteFromWaitingWriter

protected boolean startWriteFromWaitingWriter()

writeLock

public Sync writeLock()