Class ConcurrentCircularArrayQueue<E>

Type Parameters:
E - the element type
All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>, MessagePassingQueue<E>
Direct Known Subclasses:
ConcurrentSequencedCircularArrayQueue, SpmcArrayQueueL1Pad, SpscArrayQueueColdField

@SuppressAnimalSniffer public abstract class ConcurrentCircularArrayQueue<E> extends ConcurrentCircularArrayQueueL0Pad<E>
A concurrent access enabling class used by circular array based queues this class exposes an offset computation method along with differently memory fenced load/store methods into the underlying array. The class is pre-padded and the array is padded on either side to help with False sharing prevention. It is expected that subclasses handle post padding.

Offset calculation is separate from access to enable the reuse of a give compute offset.

Load/Store methods using a buffer parameter are provided to allow the prevention of final field reload after a LoadLoad barrier.

  • Field Details

    • SPARSE_SHIFT

      protected static final int SPARSE_SHIFT
    • BUFFER_PAD

      protected static final int BUFFER_PAD
      See Also:
    • REF_ARRAY_BASE

      private static final long REF_ARRAY_BASE
    • REF_ELEMENT_SHIFT

      private static final int REF_ELEMENT_SHIFT
    • mask

      protected final long mask
    • buffer

      protected final E[] buffer
  • Constructor Details

    • ConcurrentCircularArrayQueue

      public ConcurrentCircularArrayQueue(int capacity)
  • Method Details

    • calcElementOffset

      protected final long calcElementOffset(long index)
      Parameters:
      index - desirable element index
      Returns:
      the offset in bytes within the array for a given index.
    • calcElementOffset

      protected final long calcElementOffset(long index, long mask)
      Parameters:
      index - desirable element index
      mask -
      Returns:
      the offset in bytes within the array for a given index.
    • spElement

      protected final void spElement(long offset, E e)
      A plain store (no ordering/fences) of an element to a given offset
      Parameters:
      offset - computed via calcElementOffset(long)
      e - a kitty
    • spElement

      protected final void spElement(E[] buffer, long offset, E e)
      A plain store (no ordering/fences) of an element to a given offset
      Parameters:
      buffer - this.buffer
      offset - computed via calcElementOffset(long)
      e - an orderly kitty
    • soElement

      protected final void soElement(long offset, E e)
      An ordered store(store + StoreStore barrier) of an element to a given offset
      Parameters:
      offset - computed via calcElementOffset(long)
      e - an orderly kitty
    • soElement

      protected final void soElement(E[] buffer, long offset, E e)
      An ordered store(store + StoreStore barrier) of an element to a given offset
      Parameters:
      buffer - this.buffer
      offset - computed via calcElementOffset(long)
      e - an orderly kitty
    • lpElement

      protected final E lpElement(long offset)
      A plain load (no ordering/fences) of an element from a given offset.
      Parameters:
      offset - computed via calcElementOffset(long)
      Returns:
      the element at the offset
    • lpElement

      protected final E lpElement(E[] buffer, long offset)
      A plain load (no ordering/fences) of an element from a given offset.
      Parameters:
      buffer - this.buffer
      offset - computed via calcElementOffset(long)
      Returns:
      the element at the offset
    • lvElement

      protected final E lvElement(long offset)
      A volatile load (load + LoadLoad barrier) of an element from a given offset.
      Parameters:
      offset - computed via calcElementOffset(long)
      Returns:
      the element at the offset
    • lvElement

      protected final E lvElement(E[] buffer, long offset)
      A volatile load (load + LoadLoad barrier) of an element from a given offset.
      Parameters:
      buffer - this.buffer
      offset - computed via calcElementOffset(long)
      Returns:
      the element at the offset
    • iterator

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

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Overrides:
      clear in class AbstractQueue<E>