|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.runtime.Interlock
public class Interlock
A synchronization primitive which allows a producer and a consumer to use the same resources without treading on each other's feet.
At most one of the producer and consumer has access at a time. The synchronization ensures that the call sequence is as follows:
beginWriting()
(called by producer) endWriting()
(called by producer) beginReading()
(called by consumer) endReading()
(called by consumer)
ExclusivePipe
is a simple extension to this class containing a
ByteBuffer
as the shared resource.
Field Summary | |
---|---|
private Semaphore |
empty
The producer notifies empty every time it finishes writing. |
private Semaphore |
full
The consumer notifies full every time it finishes reading. |
Constructor Summary | |
---|---|
Interlock()
|
Method Summary | |
---|---|
void |
beginReading()
Acquires the buffer, in preparation for reading. |
void |
beginWriting()
Acquires the buffer, in preparation for writing. |
void |
endReading()
Releases the buffer after reading its contents. |
void |
endWriting()
Releases the buffer after writing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Semaphore empty
empty
every time it finishes writing.
The consumer waits for it.
private final Semaphore full
full
every time it finishes reading.
The producer waits for it, then starts work.
Constructor Detail |
---|
public Interlock()
Method Detail |
---|
public void beginWriting()
The producer should call this method. After this call completes, the
consumer's call to beginReading()
will block until the producer
has called endWriting()
.
public void endWriting()
The producer should call this method. After this call completes, the
producers's call to beginWriting()
will block until the consumer
has called beginReading()
followed by endReading()
.
public void beginReading()
After this call completes, the producer's call to beginWriting()
will block until the consumer has called endReading()
.
public void endReading()
The consumer should call this method. After this call completes, the
consumer's call to beginReading()
will block until the producer
has called beginWriting()
followed by endWriting()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |