Class BaseMpscLinkedArrayQueue<E>

All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>
Direct Known Subclasses:
MpscChunkedArrayQueueColdProducerFields

abstract class BaseMpscLinkedArrayQueue<E> extends BaseMpscLinkedArrayQueueColdProducerFields<E>
  • Field Details

    • P_INDEX_OFFSET

      private static final long P_INDEX_OFFSET
    • C_INDEX_OFFSET

      private static final long C_INDEX_OFFSET
    • P_LIMIT_OFFSET

      private static final long P_LIMIT_OFFSET
    • JUMP

      private static final Object JUMP
  • Constructor Details

    • BaseMpscLinkedArrayQueue

      BaseMpscLinkedArrayQueue(int initialCapacity)
      Parameters:
      initialCapacity - the queue initial capacity. If chunk size is fixed this will be the chunk size. Must be 2 or more.
  • Method Details

    • iterator

      public final Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in class AbstractCollection<E>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<E>
    • offer

      public boolean offer(E e)
    • offerSlowPath

      private int offerSlowPath(long mask, long pIndex, long producerLimit)
      We do not inline resize into this method because we do not resize on fill.
    • availableInQueue

      protected abstract long availableInQueue(long pIndex, long cIndex)
      Returns:
      available elements in queue * 2
    • modifiedCalcElementOffset

      private static long modifiedCalcElementOffset(long index, long mask)
      This method assumes index is actually (index invalid input: '<'invalid input: '<' 1) because lower bit is used for resize. This is compensated for by reducing the element shift. The computation is constant folded, so there's no cost.
    • 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.

    • getNextBuffer

      private E[] getNextBuffer(E[] buffer, long mask)
    • nextArrayOffset

      private static long nextArrayOffset(long mask)
    • newBufferPoll

      private E newBufferPoll(E[] nextBuffer, long index)
    • newBufferPeek

      private E newBufferPeek(E[] nextBuffer, long index)
    • newBufferAndOffset

      private long newBufferAndOffset(E[] nextBuffer, long index)
    • size

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

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

      private long lvProducerIndex()
    • lvConsumerIndex

      private long lvConsumerIndex()
    • soProducerIndex

      private void soProducerIndex(long v)
    • casProducerIndex

      private boolean casProducerIndex(long expect, long newValue)
    • soConsumerIndex

      private void soConsumerIndex(long v)
    • lvProducerLimit

      private long lvProducerLimit()
    • casProducerLimit

      private boolean casProducerLimit(long expect, long newValue)
    • soProducerLimit

      private void soProducerLimit(long v)
    • currentProducerIndex

      public long currentProducerIndex()
    • currentConsumerIndex

      public long currentConsumerIndex()
    • capacity

      public abstract int capacity()
    • relaxedOffer

      public boolean relaxedOffer(E e)
    • relaxedPoll

      public E relaxedPoll()
    • relaxedPeek

      public E relaxedPeek()
    • resize

      private void resize(long oldMask, E[] oldBuffer, long pIndex, E e)
    • allocate

      public static <E> E[] allocate(int capacity)
    • getNextBufferSize

      protected abstract int getNextBufferSize(E[] buffer)
      Returns:
      next buffer size(inclusive of next array pointer)
    • getCurrentBufferCapacity

      protected abstract long getCurrentBufferCapacity(long mask)
      Returns:
      current buffer capacity for elements (excluding next pointer and jump entry) * 2