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:
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final E[]
protected static final int
protected final long
private static final long
private static final int
protected static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final long
calcElementOffset
(long index) protected final long
calcElementOffset
(long index, long mask) void
clear()
iterator()
protected final E
lpElement
(long offset) A plain load (no ordering/fences) of an element from a given offset.protected final E
A plain load (no ordering/fences) of an element from a given offset.protected final E
lvElement
(long offset) A volatile load (load + LoadLoad barrier) of an element from a given offset.protected final E
A volatile load (load + LoadLoad barrier) of an element from a given offset.protected final void
An ordered store(store + StoreStore barrier) of an element to a given offsetprotected final void
An ordered store(store + StoreStore barrier) of an element to a given offsetprotected final void
A plain store (no ordering/fences) of an element to a given offsetprotected final void
A plain store (no ordering/fences) of an element to a given offsetMethods inherited from class java.util.AbstractQueue
add, addAll, element, remove
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 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
-
-
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 indexmask
-- Returns:
- the offset in bytes within the array for a given index.
-
spElement
A plain store (no ordering/fences) of an element to a given offset- Parameters:
offset
- computed viacalcElementOffset(long)
e
- a kitty
-
spElement
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
An ordered store(store + StoreStore barrier) of an element to a given offset- Parameters:
offset
- computed viacalcElementOffset(long)
e
- an orderly kitty
-
soElement
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
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
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
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
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
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Overrides:
clear
in classAbstractQueue<E>
-