T
- the contained value typepublic final class MpscLinkedQueue<T> extends Object implements SimplePlainQueue<T>
Constructor and Description |
---|
MpscLinkedQueue() |
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 v1,
T v2)
Atomically enqueue two values.
|
T |
poll()
Tries to dequeue a value (non-null) or returns null if
the queue is empty.
|
public boolean offer(T e)
IMPLEMENTATION NOTES:
Offer is allowed from multiple threads.
Offer allocates a new node and:
offer
in interface SimpleQueue<T>
e
- the value to enqueue, not nullQueue.offer(java.lang.Object)
@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.
IMPLEMENTATION NOTES:
Poll is allowed from a SINGLE thread.
Poll reads the next node from the consumerNode and:
poll
in interface SimplePlainQueue<T>
poll
in interface SimpleQueue<T>
Queue.poll()
public boolean offer(T v1, T v2)
SimpleQueue
offer
in interface SimpleQueue<T>
v1
- the first value to enqueue, not nullv2
- the second value to enqueue, not nullpublic void clear()
SimpleQueue
clear
in interface SimpleQueue<T>
public boolean isEmpty()
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).
IMPLEMENTATION NOTES:
Queue is empty when producerNode is the same as consumerNode. An alternative implementation would be to observe
the producerNode.value is null, which also means an empty queue because only the consumerNode.value is allowed to
be null.
isEmpty
in interface SimpleQueue<T>
Copyright © 2022–2023. All rights reserved.