Package rx.internal.util.unsafe
Class ConcurrentCircularArrayQueue<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- rx.internal.util.unsafe.ConcurrentCircularArrayQueueL0Pad<E>
-
- rx.internal.util.unsafe.ConcurrentCircularArrayQueue<E>
-
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.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 Summary
Fields Modifier and Type Field Description protected E[]
buffer
protected static int
BUFFER_PAD
protected long
mask
private static long
REF_ARRAY_BASE
private static int
REF_ELEMENT_SHIFT
protected static int
SPARSE_SHIFT
-
Constructor Summary
Constructors Constructor Description ConcurrentCircularArrayQueue(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected long
calcElementOffset(long index)
protected long
calcElementOffset(long index, long mask)
void
clear()
java.util.Iterator<E>
iterator()
protected E
lpElement(long offset)
A plain load (no ordering/fences) of an element from a given offset.protected E
lpElement(E[] buffer, long offset)
A plain load (no ordering/fences) of an element from a given offset.protected E
lvElement(long offset)
A volatile load (load + LoadLoad barrier) of an element from a given offset.protected E
lvElement(E[] buffer, long offset)
A volatile load (load + LoadLoad barrier) of an element from a given offset.protected void
soElement(long offset, E e)
An ordered store(store + StoreStore barrier) of an element to a given offsetprotected void
soElement(E[] buffer, long offset, E e)
An ordered store(store + StoreStore barrier) of an element to a given offsetprotected void
spElement(long offset, E e)
A plain store (no ordering/fences) of an element to a given offsetprotected void
spElement(E[] buffer, long offset, E e)
A plain store (no ordering/fences) of an element to a given offset-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Field Detail
-
SPARSE_SHIFT
protected static final int SPARSE_SHIFT
-
BUFFER_PAD
protected static final int BUFFER_PAD
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
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 indexmask
-- 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 viacalcElementOffset(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.bufferoffset
- computed viacalcElementOffset(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 viacalcElementOffset(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.bufferoffset
- computed viacalcElementOffset(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 viacalcElementOffset(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.bufferoffset
- computed viacalcElementOffset(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 viacalcElementOffset(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.bufferoffset
- computed viacalcElementOffset(long)
- Returns:
- the element at the offset
-
iterator
public java.util.Iterator<E> iterator()
-
-