Class SpscAtomicArrayQueue<E>

Type Parameters:
E -
All Implemented Interfaces:
Iterable<E>, Collection<E>, 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 Details

    • MAX_LOOK_AHEAD_STEP

      private static final Integer MAX_LOOK_AHEAD_STEP
    • producerIndex

      final AtomicLong producerIndex
    • producerLookAhead

      long producerLookAhead
    • consumerIndex

      final AtomicLong consumerIndex
    • lookAheadStep

      final int lookAheadStep
  • Constructor Details

    • SpscAtomicArrayQueue

      public SpscAtomicArrayQueue(int capacity)
  • Method Details

    • offer

      public boolean offer(E e)
    • poll

      public E poll()
    • peek

      public E peek()
    • size

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

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

      private void soProducerIndex(long newIndex)
    • soConsumerIndex

      private void soConsumerIndex(long newIndex)
    • lvConsumerIndex

      private long lvConsumerIndex()
    • lvProducerIndex

      private long lvProducerIndex()