Class SpscAtomicArrayQueue<E>

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


    public final class SpscAtomicArrayQueue<E>
    extends AbstractQueue<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

      • producerLookAhead

        protected long producerLookAhead
      • mask

        protected final int mask
    • 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()
      • iterator

        public Iterator<E> iterator()
      • clear

        public void clear()
      • calcElementOffset

        protected final int calcElementOffset(long index,
                                              int mask)
      • calcElementOffset

        protected final int calcElementOffset(long index)
      • lpElement

        protected final E lpElement(int offset)
      • spElement

        protected final void spElement(int offset,
                                       E value)
      • soElement

        protected final void soElement(int offset,
                                       E value)
      • lvElement

        protected final E lvElement(int offset)