Class SpscAtomicArrayQueue<E>

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

    public final class SpscAtomicArrayQueue<E>
    extends AtomicReferenceArrayQueue<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), and adjusted to comply with Queue.offer semantics with regards to capacity.
    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

      • MAX_LOOK_AHEAD_STEP

        private static final java.lang.Integer MAX_LOOK_AHEAD_STEP
      • producerIndex

        final java.util.concurrent.atomic.AtomicLong producerIndex
      • producerLookAhead

        long producerLookAhead
      • consumerIndex

        final java.util.concurrent.atomic.AtomicLong consumerIndex
      • lookAheadStep

        final int lookAheadStep
    • Constructor Detail

      • SpscAtomicArrayQueue

        public SpscAtomicArrayQueue​(int capacity)
    • Method Detail

      • offer

        public boolean offer​(E e)
      • poll

        public E poll()
      • peek

        public E peek()
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • soProducerIndex

        private void soProducerIndex​(long newIndex)
      • soConsumerIndex

        private void soConsumerIndex​(long newIndex)
      • lvConsumerIndex

        private long lvConsumerIndex()
      • lvProducerIndex

        private long lvProducerIndex()