T
- the contained value typepublic final class SpscLinkedArrayQueue<T> extends Object implements SimplePlainQueue<T>
Constructor and Description |
---|
SpscLinkedArrayQueue(int bufferSize)
Constructs a linked array-based queue instance with the given
island size rounded up to the next power of 2.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all enqueued items from this queue.
|
boolean |
isEmpty()
Returns true if the queue is empty.
|
boolean |
offer(T e)
Atomically enqueue a single value.
|
boolean |
offer(T first,
T second)
Offer two elements at the same time.
|
T |
peek()
Returns the next element in this queue without removing it or
null
if this queue is empty |
T |
poll()
Tries to dequeue a value (non-null) or returns null if
the queue is empty.
|
int |
size()
Returns the number of elements in the queue.
|
public SpscLinkedArrayQueue(int bufferSize)
bufferSize
- the maximum number of elements per islandpublic boolean offer(T e)
This implementation is correct for single producer thread use only.
offer
in interface SimpleQueue<T>
e
- the value to enqueue, not null@Nullable public T poll()
If the producer uses SimpleQueue.offer(Object, Object)
and
when polling in pairs, if the first poll() returns a non-null
item, the second poll() is guaranteed to return a non-null item
as well.
This implementation is correct for single consumer thread use only.
poll
in interface SimplePlainQueue<T>
poll
in interface SimpleQueue<T>
@Nullable public T peek()
null
if this queue is emptynull
public void clear()
SimpleQueue
clear
in interface SimpleQueue<T>
public int size()
public boolean isEmpty()
SimpleQueue
Note however that due to potential fused functions in SimpleQueue.poll()
it is possible this method returns false but then poll() returns null
because the fused function swallowed the available item(s).
isEmpty
in interface SimpleQueue<T>
public boolean offer(T first, T second)
Don't use the regular offer() with this at all!
offer
in interface SimpleQueue<T>
first
- the first value, not nullsecond
- the second value, not null