Class SpscLinkedUnpaddedQueue<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>, MessagePassingQueue<E>
- Use inheritance to ensure no false sharing occurs between producer/consumer node reference fields.
- As this is an SPSC we have no need for XCHG, an ordered store is enough.
-
Nested Class Summary
Nested classes/interfaces inherited from interface MessagePassingQueue
MessagePassingQueue.Consumer<T>, MessagePassingQueue.ExitCondition, MessagePassingQueue.Supplier<T>, MessagePassingQueue.WaitStrategy -
Field Summary
Fields inherited from class BaseLinkedUnpaddedQueueProducerNodeRef
P_NODE_OFFSETFields inherited from interface MessagePassingQueue
UNBOUNDED_CAPACITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintStuff the queue with elements from the supplier.intfill(MessagePassingQueue.Supplier<E> s, int limit) Stuff the queue with up to limit elements from the supplier.voidfill(MessagePassingQueue.Supplier<E> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit) Stuff the queue with elements from the supplier forever.booleanCalled from a producer thread subject to the restrictions appropriate to the implementation and according to theQueue.offer(Object)interface.Methods inherited from class BaseLinkedUnpaddedQueue
capacity, drain, drain, drain, getSingleConsumerNodeValue, isEmpty, iterator, newNode, newNode, peek, poll, relaxedOffer, relaxedPeek, relaxedPoll, size, spinWaitForNextNode, toStringMethods inherited from class BaseLinkedUnpaddedQueueConsumerNodeRef
lpConsumerNode, lvConsumerNode, spConsumerNodeMethods inherited from class BaseLinkedUnpaddedQueueProducerNodeRef
casProducerNode, lpProducerNode, lvProducerNode, soProducerNode, spProducerNodeMethods inherited from class AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArrayMethods inherited from interface MessagePassingQueue
clear
-
Constructor Details
-
SpscLinkedUnpaddedQueue
public SpscLinkedUnpaddedQueue()
-
-
Method Details
-
offer
Called from a producer thread subject to the restrictions appropriate to the implementation and according to theQueue.offer(Object)interface.
IMPLEMENTATION NOTES:
Offer is allowed from a SINGLE thread.
Offer allocates a new node (holding the offered value) and:- Sets the new node as the producerNode
- Sets that node as the lastProducerNode.next
- Parameters:
e- notnull, will throw NPE if it is- Returns:
- true if element was inserted into the queue, false iff full
- See Also:
-
fill
Description copied from interface:MessagePassingQueueStuff the queue with elements from the supplier. Semantically similar to: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.- Returns:
- the number of offered elements
-
fill
Description copied from interface:MessagePassingQueueStuff the queue with up to limit elements from the supplier. Semantically similar to: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.- Returns:
- the number of offered elements
-
fill
public void fill(MessagePassingQueue.Supplier<E> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit) Description copied from interface:MessagePassingQueueStuff the queue with elements from the supplier forever. Semantically similar to: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 toMessagePassingQueue.Supplier.get()make sure you have read and understood these before using this method.
-