javax.realtime
Class WaitFreeDequeue

java.lang.Object
  |
  +--javax.realtime.WaitFreeDequeue

public class WaitFreeDequeue
extends java.lang.Object

The wait-free classes facilitate communication and synchronization between instances of RealtimeThread and Thread.


Field Summary
protected  int currentIndex
           
protected  javax.realtime.MemoryArea memArea
           
protected  java.lang.Object[] queue
           
protected  int queueSize
           
protected  java.lang.Thread readerThread
           
protected  java.lang.Thread writerThread
           
 
Constructor Summary
WaitFreeDequeue(java.lang.Thread writer, java.lang.Thread reader, int maximum, javax.realtime.MemoryArea area)
          A queue with unsynchronized and nonblocking read() and write() methods and synchronized and blocking read() and write() methods.
 
Method Summary
 java.lang.Object blockingRead()
          A synchronized call of the read() method of the underlying WaitFreeWriteQueue.
 boolean blockingWrite(java.lang.Object object)
          A synchronized call of the write() method of the underlying WaitFreeReadQueue.
 boolean force(java.lang.Object object)
          If this is full then this call overwrites the last object written to this with the given object.
private  boolean isEmpty()
          Used to check if the queue is empty.
private  boolean isFull()
          Used to check if the queue is full.
 java.lang.Object nonBlockingRead()
          An unsynchronized call of the read() method of the underlying WaitFreeReadQueue.
 boolean nonBlockingWrite(java.lang.Object object)
          An unsynchronized call of the write() method of the underlying WaitFreeWriteQueue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected java.lang.Object[] queue

queueSize

protected int queueSize

currentIndex

protected int currentIndex

writerThread

protected java.lang.Thread writerThread

readerThread

protected java.lang.Thread readerThread

memArea

protected javax.realtime.MemoryArea memArea
Constructor Detail

WaitFreeDequeue

public WaitFreeDequeue(java.lang.Thread writer,
                       java.lang.Thread reader,
                       int maximum,
                       javax.realtime.MemoryArea area)
                throws java.lang.IllegalArgumentException
A queue with unsynchronized and nonblocking read() and write() methods and synchronized and blocking read() and write() methods.

Parameters:
writer - An instance of Thread.
reader - An instance of Thread.
maximum - The maximum number of elements in both the WaitFreeReadQueue and the WaitFreeWriteQueue.
area - The MemoryArea in which this object and internal elements are allocated
Throws:
java.lang.IllegalArgumentException - If an argument holds an invalid value. The current memory areas of writer, reader, and memory must be compatible with respect to the assignment and access rules for memory areas.
Method Detail

isEmpty

private boolean isEmpty()
Used to check if the queue is empty.

Returns:
True, if the queue is empty. False, if it is not.

isFull

private boolean isFull()
Used to check if the queue is full.

Returns:
True, if the queue is full. False, if it is not.

blockingRead

public java.lang.Object blockingRead()
A synchronized call of the read() method of the underlying WaitFreeWriteQueue. This call blocks on queue empty and will wait until there is an element in the queue to return.

Returns:
The java.lang.Object read.

blockingWrite

public boolean blockingWrite(java.lang.Object object)
                      throws MemoryScopeException
A synchronized call of the write() method of the underlying WaitFreeReadQueue. This call blocks on queue full and waits until there is space in this.

Parameters:
object - The java.lang.Object to place in this.
Returns:
True, if the write succeeded. False, if not.
Throws:
MemoryScopeException - If the write causes an access or assignment violation.

force

public boolean force(java.lang.Object object)
If this is full then this call overwrites the last object written to this with the given object. If this is not full this call is equivalent to the nonBlockingWrite() call.

Parameters:
object - The java.lang.Object which will overwrite the last object if this is full. Otherwise object will be placed in thisReturns:
True, if an element was overwritten. False, if there is an empty element into which the write occured.

nonBlockingRead

public java.lang.Object nonBlockingRead()
An unsynchronized call of the read() method of the underlying WaitFreeReadQueue.

Returns:
A java.lang.Object object read from this. If there are no elements in this then null is returned.

nonBlockingWrite

public boolean nonBlockingWrite(java.lang.Object object)
                         throws MemoryScopeException
An unsynchronized call of the write() method of the underlying WaitFreeWriteQueue. This call does not block on queue full.

Parameters:
object - The java.lang.Object to attempt to place in this.
Returns:
True, if the object is now in this, otherwise returns false.
Throws:
MemoryScopeException - If the write causes an access or assignment violation.