javax.realtime
Class WaitFreeReadQueue

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

public class WaitFreeReadQueue
extends java.lang.Object

The wait-free queue class facilitate communication and synchronization between instances of RealtimeThread and Thread. The problem is that synchronized access objects shared between real-time threads and threads might cause the real-time threads to incur delays due to execution of the garbage collector.

The read() method of this class does not block on an imagined queue-empty condition variable. If the read() is called on an empty queue null is returned. If two real-time threads intend to read from this queue they must provide their own synchronization.

The write() method of this queue is synchronized and may be called by more than one writer and will block on queue empty.


Field Summary
protected  int currentIndex
           
protected  javax.realtime.MemoryArea memArea
           
protected  boolean notify
           
protected  int queueSize
           
protected  java.lang.Thread readerThread
           
protected  java.lang.Object[] readQueue
           
protected  java.lang.Thread writerThread
           
 
Constructor Summary
WaitFreeReadQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, javax.realtime.MemoryArea memory)
          A queue with an unsynchronizes and nonblocking read() method and a synchronized and blocking write() method.
WaitFreeReadQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, javax.realtime.MemoryArea memory, boolean notify)
          A queue with an unsynchronizes and nonblocking read() method and a synchronized and blocking write() method.
 
Method Summary
 void clear()
          Set this to empty.
 boolean isEmpty()
          Queries the system to determine if this is empty.
 boolean isFull()
          Queries the system to determine if this is full.
 java.lang.Object read()
          Reads the next element in the queue unless the queue is empty.
 int size()
          Queries the system to determine the number of elements in this.
 void waitForData()
          If this is empty waitForData() waits on the event until the writer inserts data.
 boolean write(java.lang.Object object)
          The synchronized and blocking write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

notify

protected boolean notify

readQueue

protected java.lang.Object[] readQueue

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

WaitFreeReadQueue

public WaitFreeReadQueue(java.lang.Thread writer,
                         java.lang.Thread reader,
                         int maximum,
                         javax.realtime.MemoryArea memory)
                  throws java.lang.IllegalArgumentException
A queue with an unsynchronizes and nonblocking read() method and a synchronized and blocking write() method.

Parameters:
writer - An instance of java.lang.Thread.
reader - An instance of java.lang.Thread.
maximum - The maximum number of elements in the queue.
memory - The MemoryArea in which this object and internal elements are alocated.
Throws:
java.lang.IllegalArgumentException

WaitFreeReadQueue

public WaitFreeReadQueue(java.lang.Thread writer,
                         java.lang.Thread reader,
                         int maximum,
                         javax.realtime.MemoryArea memory,
                         boolean notify)
                  throws java.lang.IllegalArgumentException
A queue with an unsynchronizes and nonblocking read() method and a synchronized and blocking write() method.

Parameters:
writer - An instance of java.lang.Thread.
reader - An instance of java.lang.Thread.
maximum - The maximum number of elements in the queue.
memory - The MemoryArea in which this object and internal elements are alocated.
notify - Whether or not the reader is notified when data is added.
Throws:
java.lang.IllegalArgumentException
Method Detail

clear

public void clear()
Set this to empty.


isEmpty

public boolean isEmpty()
Queries the system to determine if this is empty.

Returns:
True, if this is empty. False, if this is not empty.

isFull

public boolean isFull()
Queries the system to determine if this is full.

Returns:
True, if this is full. False, if this is not full.

read

public java.lang.Object read()
Reads the next element in the queue unless the queue is empty. If the queue is empty null is returned.

Returns:
The instance of java.lang.Object read. Null, if this was empty.

size

public int size()
Queries the system to determine the number of elements in this.

Returns:
An integer which is the number of non-empty positions in this.

waitForData

public void waitForData()
If this is empty waitForData() waits on the event until the writer inserts data. Note that true priority inversion does not occur since the writer locks a different object and the notify is executed by the AsyncEventHandler which has noHeap characteristics.


write

public boolean write(java.lang.Object object)
              throws MemoryScopeException
The synchronized and blocking write. This call blocks on queue full and will wait until there is space in the queue.

Parameters:
object - The java.lang.Object that is placed in this.
Returns:
True, if the write occured. False, if it did not.
Throws:
MemoryScopeException