Class SpscArrayQueue<E>

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


    public final class SpscArrayQueue<E>
    extends ConcurrentCircularArrayQueue<E>
    A Single-Producer-Single-Consumer queue backed by a pre-allocated buffer.
    This implementation is a mashup of the Fast Flow algorithm with an optimization of the offer method taken from the BQueue algorithm (a variation on Fast Flow).
    For convenience the relevant papers are available in the resources folder:
    2010 - Pisa - SPSC Queues on Shared Cache Multi-Core Systems.pdf
    2012 - Junchang- BQueue- Efficient and Practical Queuing.pdf
    This implementation is wait free.
    • Field Detail

      • consumerIndex

        protected long consumerIndex
      • producerIndex

        protected long producerIndex
      • producerLookAhead

        protected long producerLookAhead
      • lookAheadStep

        protected final int lookAheadStep
    • Constructor Detail

      • SpscArrayQueue

        public SpscArrayQueue(int capacity)
    • Method Detail

      • offer

        public boolean offer(E e)

        This implementation is correct for single producer thread use only.

      • poll

        public E poll()

        This implementation is correct for single consumer thread use only.

      • peek

        public E peek()

        This implementation is correct for single consumer thread use only.

      • size

        public int size()
      • lvConsumerIndex

        protected final long lvConsumerIndex()
      • lvProducerIndex

        protected final long lvProducerIndex()
      • isEmpty

        public boolean isEmpty()
        This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
        Returns:
        true if empty, false otherwise