Class SpscUnboundedArrayQueue<E>

    • Field Detail

      • MAX_LOOK_AHEAD_STEP

        static final int MAX_LOOK_AHEAD_STEP
      • P_INDEX_OFFSET

        private static final long P_INDEX_OFFSET
      • C_INDEX_OFFSET

        private static final long C_INDEX_OFFSET
      • REF_ARRAY_BASE

        private static final long REF_ARRAY_BASE
      • REF_ELEMENT_SHIFT

        private static final int REF_ELEMENT_SHIFT
      • HAS_NEXT

        private static final java.lang.Object HAS_NEXT
    • Constructor Detail

      • SpscUnboundedArrayQueue

        public SpscUnboundedArrayQueue​(int bufferSize)
    • 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>
      • offer

        public final boolean offer​(E e)

        This implementation is correct for single producer thread use only.

        Specified by:
        offer in interface java.util.Queue<E>
      • writeToQueue

        private boolean writeToQueue​(E[] buffer,
                                     E e,
                                     long index,
                                     long offset)
      • resize

        private void resize​(E[] oldBuffer,
                            long currIndex,
                            long offset,
                            E e,
                            long mask)
      • soNext

        private void soNext​(E[] curr,
                            E[] next)
      • lvNext

        private E[] lvNext​(E[] curr)
      • poll

        public final E poll()

        This implementation is correct for single consumer thread use only.

        Specified by:
        poll in interface java.util.Queue<E>
      • newBufferPoll

        private E newBufferPoll​(E[] nextBuffer,
                                long index,
                                long mask)
      • peek

        public final E peek()

        This implementation is correct for single consumer thread use only.

        Specified by:
        peek in interface java.util.Queue<E>
      • newBufferPeek

        private E newBufferPeek​(E[] nextBuffer,
                                long index,
                                long mask)
      • size

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

        private void adjustLookAheadStep​(int capacity)
      • lvProducerIndex

        private long lvProducerIndex()
      • lvConsumerIndex

        private long lvConsumerIndex()
      • soProducerIndex

        private void soProducerIndex​(long v)
      • soConsumerIndex

        private void soConsumerIndex​(long v)
      • calcWrappedOffset

        private static long calcWrappedOffset​(long index,
                                              long mask)
      • calcDirectOffset

        private static long calcDirectOffset​(long index)
      • soElement

        private static void soElement​(java.lang.Object[] buffer,
                                      long offset,
                                      java.lang.Object e)
      • lvElement

        private static <E> java.lang.Object lvElement​(E[] buffer,
                                                      long offset)
      • currentProducerIndex

        public long currentProducerIndex()
        Description copied from interface: QueueProgressIndicators
        This method has no concurrent visibility semantics. The value returned may be negative. Under normal circumstances 2 consecutive calls to this method can offer an idea of progress made by producer threads by subtracting the 2 results though in extreme cases (if producers have progressed by more than 2^64) this may also fail.
        This value will normally indicate number of elements passed into the queue, but may under some circumstances be a derivative of that figure. This method should not be used to derive size or emptiness.
        Specified by:
        currentProducerIndex in interface QueueProgressIndicators
        Returns:
        the current value of the producer progress index
      • currentConsumerIndex

        public long currentConsumerIndex()
        Description copied from interface: QueueProgressIndicators
        This method has no concurrent visibility semantics. The value returned may be negative. Under normal circumstances 2 consecutive calls to this method can offer an idea of progress made by consumer threads by subtracting the 2 results though in extreme cases (if consumers have progressed by more than 2^64) this may also fail.
        This value will normally indicate number of elements taken out of the queue, but may under some circumstances be a derivative of that figure. This method should not be used to derive size or emptiness.
        Specified by:
        currentConsumerIndex in interface QueueProgressIndicators
        Returns:
        the current value of the consumer progress index