Class SpscLinkedAtomicQueue<E>

Type Parameters:
E -
All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>, MessagePassingQueue<E>

public class SpscLinkedAtomicQueue<E> extends BaseLinkedAtomicQueue<E>
NOTE: This class was automatically generated by org.jctools.queues.atomic.JavaParsingAtomicLinkedQueueGenerator which can found in the jctools-build module. The original source file is SpscLinkedQueue.java. 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. Use inheritance to ensure no false sharing occurs between producer/consumer node reference fields.
  2. 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.
  • Constructor Details

    • SpscLinkedAtomicQueue

      public SpscLinkedAtomicQueue()
  • Method Details

    • offer

      public 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.

      IMPLEMENTATION NOTES:
      Offer is allowed from a SINGLE thread.
      Offer allocates a new node (holding the offered value) and:

      1. Sets the new node as the producerNode
      2. Sets that node as the lastProducerNode.next
      From this follows that producerNode.next is always null and for all other nodes node.next is not null.
      Parameters:
      e - not null, will throw NPE if it is
      Returns:
      true if element was inserted into the queue, false iff full
      See Also:
    • fill

      public int fill(MessagePassingQueue.Supplier<E> s)
      Description copied from interface: MessagePassingQueue
      Stuff 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

      public int fill(MessagePassingQueue.Supplier<E> s, int limit)
      Description copied from interface: MessagePassingQueue
      Stuff 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

      Description copied from interface: MessagePassingQueue
      Stuff 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 to MessagePassingQueue.Supplier.get() make sure you have read and understood these before using this method.