|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.realtime.WaitFreeWriteQueue
The wait-free queue facilitate communication and synchronization
between instances of RealtimeThread
and
java.lang.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 write()
method of this class does not block on
an imagined queue-full condition variable. If the write()
method is called on a full queue false is returned. If two real-time
threads intend to read from this queue they must provide their
own synchronization.
The read()
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 int |
queueSize
|
protected java.lang.Thread |
readerThread
|
protected java.lang.Object[] |
writeQueue
|
protected java.lang.Thread |
writerThread
|
Constructor Summary | |
WaitFreeWriteQueue(java.lang.Thread writer,
java.lang.Thread reader,
int maximum,
javax.realtime.MemoryArea memory)
A queue with an unsynchronized and nonblocking write()
method and a synchronized and blocking read() method. |
Method Summary | |
void |
clear()
Set this to empty. |
boolean |
force(java.lang.Object object)
Force this java.lang.Object to replace the last one. |
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()
A synchronized read on the queue. |
int |
size()
Queries the system to determine the number of elements in this . |
boolean |
write(java.lang.Object object)
Attempt to insert an element into the queue. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Object[] writeQueue
protected int queueSize
protected int currentIndex
protected java.lang.Thread writerThread
protected java.lang.Thread readerThread
protected javax.realtime.MemoryArea memArea
Constructor Detail |
public WaitFreeWriteQueue(java.lang.Thread writer, java.lang.Thread reader, int maximum, javax.realtime.MemoryArea memory) throws java.lang.IllegalArgumentException
write()
method and a synchronized and blocking read()
method.
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 allocated.
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 |
public void clear()
this
to empty.
public boolean force(java.lang.Object object) throws MemoryScopeException
java.lang.Object
to replace the last one.
If the reader should happen to have just removed the other
java.lang.Object
just as we were updating it, we will
return false. False may mean that it just saw that we put in there.
Either way, the best thing to do is to just write again -- which
will succeed, and check on the readers side for consecutive
identical read values.
MemoryScopeException
public boolean isEmpty()
this
is empty.
this
is empty. False, if
this
is not empty.public boolean isFull()
this
is full.
this
is full. False, if
this
is not full.public java.lang.Object read()
java.lang.Object
read or null if
this
is empty.public int size()
this
.
this
.public boolean write(java.lang.Object object) throws MemoryScopeException
object
- The java.lang.Object
to insert.
MemoryScopeException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |