public class MpscLinkedUnpaddedQueue<E> extends BaseLinkedUnpaddedQueue<E>
Queue
contract on poll. The original semantics are available via relaxedPoll.
MessagePassingQueue.Consumer<T>, MessagePassingQueue.ExitCondition, MessagePassingQueue.Supplier<T>, MessagePassingQueue.WaitStrategy
P_NODE_OFFSET
UNBOUNDED_CAPACITY
Constructor and Description |
---|
MpscLinkedUnpaddedQueue() |
Modifier and Type | Method and Description |
---|---|
int |
fill(MessagePassingQueue.Supplier<E> s)
Stuff the queue with elements from the supplier.
|
int |
fill(MessagePassingQueue.Supplier<E> s,
int limit)
Stuff the queue with up to limit elements from the supplier.
|
void |
fill(MessagePassingQueue.Supplier<E> s,
MessagePassingQueue.WaitStrategy wait,
MessagePassingQueue.ExitCondition exit)
Stuff the queue with elements from the supplier forever.
|
private LinkedQueueNode<E> |
getNextConsumerNode(LinkedQueueNode<E> currConsumerNode) |
boolean |
offer(E e)
Called from a producer thread subject to the restrictions appropriate to the implementation and
according to the
Queue.offer(Object) interface. |
boolean |
remove(java.lang.Object o) |
private LinkedQueueNode<E> |
xchgProducerNode(LinkedQueueNode<E> newVal) |
capacity, drain, drain, drain, getSingleConsumerNodeValue, isEmpty, iterator, newNode, newNode, peek, poll, relaxedOffer, relaxedPeek, relaxedPoll, size, spinWaitForNextNode, toString
lpConsumerNode, lvConsumerNode, spConsumerNode
casProducerNode, lpProducerNode, lvProducerNode, soProducerNode, spProducerNode
contains, containsAll, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
clear
public boolean offer(E e)
Queue.offer(Object)
interface.
IMPLEMENTATION NOTES:
Offer is allowed from multiple threads.
Offer allocates a new node and:
e
- not null
, will throw NPE if it isMessagePassingQueue.offer(Object)
,
Queue.offer(java.lang.Object)
public boolean remove(java.lang.Object o)
This method is only safe to call from the (single) consumer thread, and is subject to best effort when racing with producers. This method is potentially blocking when "bubble"s in the queue are visible.
public int fill(MessagePassingQueue.Supplier<E> s)
MessagePassingQueue
while(relaxedOffer(s.get());There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation.
Unbounded queues will fill up the queue with a fixed amount rather than fill up to oblivion.
WARNING: Explicit assumptions are made with regards to MessagePassingQueue.Supplier.get()
make sure you have read
and understood these before using this method.
public int fill(MessagePassingQueue.Supplier<E> s, int limit)
MessagePassingQueue
for(int i=0; i < limit && relaxedOffer(s.get()); i++);
There's no strong commitment to the queue being full at the end of a fill. Called from a producer
thread subject to the restrictions appropriate to the implementation.
WARNING: Explicit assumptions are made with regards to MessagePassingQueue.Supplier.get()
make sure you have read
and understood these before using this method.
public void fill(MessagePassingQueue.Supplier<E> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)
MessagePassingQueue
int idleCounter = 0;
while (exit.keepRunning()) {
E e = s.get();
while (!relaxedOffer(e)) {
idleCounter = wait.idle(idleCounter);
continue;
}
idleCounter = 0;
}
Called from a producer thread subject to the restrictions appropriate to the implementation. The main difference
being that implementors MUST assure room in the queue is available BEFORE calling MessagePassingQueue.Supplier.get()
.
WARNING: Explicit assumptions are made with regards to MessagePassingQueue.Supplier.get()
make sure you have read
and understood these before using this method.
private LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> newVal)
private LinkedQueueNode<E> getNextConsumerNode(LinkedQueueNode<E> currConsumerNode)