Package EDU.oswego.cs.dl.util.concurrent
Class WriterPreferenceReadWriteLock
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock
- All Implemented Interfaces:
ReadWriteLock
- Direct Known Subclasses:
ReaderPreferenceReadWriteLock
,ReentrantWriterPreferenceReadWriteLock
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
protected class
Reader and Writer requests are maintained in two different wait sets, by two different objects.protected class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
protected Thread
protected final WriterPreferenceReadWriteLock.ReaderLock
protected long
protected long
protected final WriterPreferenceReadWriteLock.WriterLock
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Override this method to change to reader preferenceprotected void
protected void
protected WriterPreferenceReadWriteLock.Signaller
endRead()
Called upon termination of a read.protected WriterPreferenceReadWriteLock.Signaller
endWrite()
Called upon termination of a write.readLock()
get the readLockprotected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
get the writeLock
-
Field Details
-
activeReaders_
protected long activeReaders_ -
activeWriter_
-
waitingReaders_
protected long waitingReaders_ -
waitingWriters_
protected long waitingWriters_ -
readerLock_
-
writerLock_
-
-
Constructor Details
-
WriterPreferenceReadWriteLock
public WriterPreferenceReadWriteLock()
-
-
Method Details
-
writeLock
Description copied from interface:ReadWriteLock
get the writeLock- Specified by:
writeLock
in interfaceReadWriteLock
-
readLock
Description copied from interface:ReadWriteLock
get the readLock- Specified by:
readLock
in interfaceReadWriteLock
-
cancelledWaitingReader
protected void cancelledWaitingReader() -
cancelledWaitingWriter
protected void cancelledWaitingWriter() -
allowReader
protected boolean allowReader()Override this method to change to reader preference -
startRead
protected boolean startRead() -
startWrite
protected boolean startWrite() -
startReadFromNewReader
protected boolean startReadFromNewReader() -
startWriteFromNewWriter
protected boolean startWriteFromNewWriter() -
startReadFromWaitingReader
protected boolean startReadFromWaitingReader() -
startWriteFromWaitingWriter
protected boolean startWriteFromWaitingWriter() -
endRead
Called upon termination of a read. Returns the object to signal to wake up a waiter, or null if no such -
endWrite
Called upon termination of a write. Returns the object to signal to wake up a waiter, or null if no such
-