Class SpscLinkedAtomicQueue<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Queue<E>

    public final class SpscLinkedAtomicQueue<E>
    extends BaseLinkedAtomicQueue<E>
    This is a weakened version of the MPSC algorithm as presented on 1024 Cores by D. Vyukov. The original has been adapted to Java and it's quirks with regards to memory model and layout:
    1. As this is an SPSC we have no need for XCHG, an ordered store is enough.
    The queue is initialized with a stub node which is set to both the producer and consumer node references. From this point follow the notes on offer/poll.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean offer​(E nextValue)

      IMPLEMENTATION NOTES:
      Offer is allowed from a SINGLE thread.
      Offer allocates a new node (holding the offered value) and: Sets that node as the producerNode.next Sets the new node as the producerNode From this follows that producerNode.next is always null and for all other nodes node.next is not null.
      E peek()  
      E poll()

      IMPLEMENTATION NOTES:
      Poll is allowed from a SINGLE thread.
      Poll reads the next node from the consumerNode and: If it is null, the queue is empty.
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, clear, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Constructor Detail

      • SpscLinkedAtomicQueue

        public SpscLinkedAtomicQueue()
    • Method Detail

      • offer

        public boolean offer​(E nextValue)

        IMPLEMENTATION NOTES:
        Offer is allowed from a SINGLE thread.
        Offer allocates a new node (holding the offered value) and:
        1. Sets that node as the producerNode.next
        2. Sets the new node as the producerNode
        From this follows that producerNode.next is always null and for all other nodes node.next is not null.
        See Also:
        Queue.offer(java.lang.Object)
      • poll

        public E poll()

        IMPLEMENTATION NOTES:
        Poll is allowed from a SINGLE thread.
        Poll reads the next node from the consumerNode and:
        1. If it is null, the queue is empty.
        2. If it is not null set it as the consumer node and return it's now evacuated value.
        This means the consumerNode.value is always null, which is also the starting point for the queue. Because null values are not allowed to be offered this is the only node with it's value set to null at any one time.
      • peek

        public E peek()