Class BaseMpscLinkedArrayQueue<E>

    • Field Detail

      • 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 java.lang.Object JUMP
    • Constructor Detail

      • BaseMpscLinkedArrayQueue

        public 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 Detail

      • iterator

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

        public java.lang.String toString()
        Overrides:
        toString in class java.util.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 << 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 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 java.util.Collection<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • isEmpty

        public final boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.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