public class WaitFreeReadQueue<T> extends Object
This class permits a thread to read from one or more other threads without being blocked by the other threads. This is required in RTSJ implementations that do not have real-time garbage collection to permit communication between NoHeapRealtimeThreads and normal Threads or RealtimeThreads to avoid the potential priority inversion problem of the NoHeapRealtimeThread being blocked waiting for another thread that itself if blocked by garbage collection activity.
In the JamaicaVM implementation, a thread that does not perform memory allocation is never blocked by the garbage collector unless it was preempted by a higher priority thread that performs memory allocation. In conjunction with the priority inversion avoidance mechanisms provided for monitors in the RTSJ (priority inheritance and priority ceiling emulation), this priority-inversion situation cannot occur in JamaicaVM, and normal protection using monitors is sufficient for the communication between NoHeapRealtimeThreads and normal Java threads. This class is consequently provided only for compatibility with other RTSJ implementations that do not provide realtime garbage collection.
Constructor and Description |
---|
WaitFreeReadQueue(int maximum,
boolean notify)
Constructor to construct a queue in immortal memory.
|
WaitFreeReadQueue(int maximum,
MemoryArea memory,
boolean notify)
Constructor to construct a queue in given memory area.
|
WaitFreeReadQueue(Runnable writer,
Runnable reader,
int maximum,
MemoryArea memory)
Constructor to construct a non-blocking read queue in given
memory area.
|
WaitFreeReadQueue(Runnable writer,
Runnable reader,
int maximum,
MemoryArea memory,
boolean notify)
Constructor to construct a non-blocking read queue in given
memory area.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
clear clears this queue.
|
boolean |
isEmpty()
isEmpty checks if the queue is currently empty.
|
boolean |
isFull()
isFull checks if the queue is currently full.
|
T |
read()
read reads the oldest element from the queue.
|
int |
size()
size returns the current size of the queue, i.e., the number of
elements that have been written but not yet read.
|
void |
waitForData()
waitForData blocks until this queue is non-empty.
|
void |
write(T object)
write writes an element to the queue.
|
public WaitFreeReadQueue(int maximum, boolean notify) throws StaticIllegalArgumentException
StaticIllegalArgumentException
- if maximum >= 0.maximum
- capacity of this queuenotify
- true to allow for blocking reads, i.e.,
notification when an element is added to an empty queue.public WaitFreeReadQueue(int maximum, MemoryArea memory, boolean notify) throws StaticIllegalArgumentException
StaticIllegalArgumentException
- if maximum <= 0 or memory ==
null.maximum
- capacity of this queuememory
- The memory area in which internal elements are
allocated.notify
- true to allow for blocking reads, i.e.,
notification when an element is added to an empty queue.public WaitFreeReadQueue(Runnable writer, Runnable reader, int maximum, MemoryArea memory) throws StaticIllegalArgumentException, MemoryScopeException
StaticIllegalArgumentException
- if maximum <= 0 or writer or
read are not referring to a Thread or a Schedulable object.MemoryScopeException
- if writer or reads is non-null and
in a memory area that is not assignment compatible with memory.writer
- A thread or schedulable object that may write to
this queue or nullreader
- A thread or schedulable object that may read from
this queue or nullmaximum
- capacity of this queuememory
- The memory area in which internal elements are
allocated, or null.public WaitFreeReadQueue(Runnable writer, Runnable reader, int maximum, MemoryArea memory, boolean notify) throws StaticIllegalArgumentException, MemoryScopeException
StaticIllegalArgumentException
- if maximum <= 0 or writer or
read are not referring to a Thread or a Schedulable object.MemoryScopeException
- if writer or reads is non-null and
in a memory area that is not assignment compatible with memory.writer
- A thread or schedulable object that may write to
this queue or nullreader
- A thread or schedulable object that may read from
this queue or nullmaximum
- capacity of this queuememory
- The memory area in which internal elements are
allocated.notify
- true to allow for blocking reads, i.e.,
notification when an element is added to an empty queue.public void clear()
public boolean isEmpty()
public boolean isFull()
public T read()
public int size()
public void waitForData() throws InterruptedException, UnsupportedOperationException
InterruptedException
- if the wait is interrupted.UnsupportedOperationException
- if this queue was
constructed with notify== false;public void write(T object) throws InterruptedException
InterruptedException
- if the wait is interrupted.object
- The object to be put in the queue.aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2019 aicas GmbH. All Rights Reserved.