Top Description Fields Constructors Methods
rx.internal.util.unsafe

public abstract Class ConcurrentCircularArrayQueue<E>

Additional top-level class in compilation unit: ConcurrentCircularArrayQueueL0Pad.

extends ConcurrentCircularArrayQueueL0Pad<E>
Class Inheritance
Known Direct Subclasses
rx.internal.util.unsafe.ConcurrentSequencedCircularArrayQueue, rx.internal.util.unsafe.SpmcArrayQueueL1Pad, rx.internal.util.unsafe.SpscArrayQueueColdField
Annotations
@SuppressAnimalSniffer
Type Parameters
<E>
the element type
Static Imports
rx.internal.util.unsafe.UnsafeAccess.UNSAFE

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.

Author
nitsanw

Field Summary

Modifier and TypeField and Description
protected final E[]
protected static final int
protected final long
private static final long
private static final int
protected static final int
Inherited from rx.internal.util.unsafe.ConcurrentCircularArrayQueueL0Pad:
p00p01p02p03p04p05p06p07p30p31p32p33p34p35p36p37

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final long

Returns:

the offset in bytes within the array for a given index.
calcElementOffset
(long
desirable element index
index
)

protected final long

Returns:

the offset in bytes within the array for a given index.
calcElementOffset
(long
desirable element index
index
,
long
the binary mask to make the index wrap around
mask
)

public void
clear()

Overrides java.util.AbstractQueue.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this queue.
public Iterator<E>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.
protected final E

Returns:

the element at the offset
lpElement
(long offset)

A plain load (no ordering/fences) of an element from a given offset.

protected final E

Returns:

the element at the offset
lpElement
(E[]
this.buffer
buffer
,
long offset)

A plain load (no ordering/fences) of an element from a given offset.

protected final E

Returns:

the element at the offset
lvElement
(long offset)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

protected final E

Returns:

the element at the offset
lvElement
(E[]
this.buffer
buffer
,
long offset)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

protected final void
soElement(long offset, E
an orderly kitty
e
)

An ordered store(store + StoreStore barrier) of an element to a given offset

protected final void
soElement(E[]
this.buffer
buffer
,
long offset, E
an orderly kitty
e
)

An ordered store(store + StoreStore barrier) of an element to a given offset

protected final void
spElement(long offset, E
a kitty
e
)

A plain store (no ordering/fences) of an element to a given offset

protected final void
spElement(E[]
this.buffer
buffer
,
long offset, E
an orderly kitty
e
)

A plain store (no ordering/fences) of an element to a given offset

Field Detail

bufferback to summary
protected final E[] buffer
BUFFER_PADback to summary
protected static final int BUFFER_PAD
maskback to summary
protected final long mask
REF_ARRAY_BASEback to summary
private static final long REF_ARRAY_BASE
REF_ELEMENT_SHIFTback to summary
private static final int REF_ELEMENT_SHIFT
SPARSE_SHIFTback to summary
protected static final int SPARSE_SHIFT

Constructor Detail

ConcurrentCircularArrayQueueback to summary
public ConcurrentCircularArrayQueue(int capacity)
Annotations
@SuppressWarnings:unchecked

Method Detail

calcElementOffsetback to summary
protected final long calcElementOffset(long index)
Parameters
index:long

desirable element index

Returns:long

the offset in bytes within the array for a given index.

calcElementOffsetback to summary
protected final long calcElementOffset(long index, long mask)
Parameters
index:long

desirable element index

mask:long

the binary mask to make the index wrap around

Returns:long

the offset in bytes within the array for a given index.

clearback to summary
public void clear()

Overrides java.util.AbstractQueue.clear.

Implements java.util.Collection.clear.

Doc from java.util.AbstractQueue.clear.

Removes all of the elements from this queue. The queue will be empty after this call returns.

This implementation repeatedly invokes poll until it returns null.

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
lpElementback to summary
protected final E lpElement(long offset)

A plain load (no ordering/fences) of an element from a given offset.

Parameters
offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

Returns:E

the element at the offset

lpElementback to summary
protected final E lpElement(E[] buffer, long offset)

A plain load (no ordering/fences) of an element from a given offset.

Parameters
buffer:E[]

this.buffer

offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

Returns:E

the element at the offset

Annotations
@SuppressWarnings:unchecked
lvElementback to summary
protected final E lvElement(long offset)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

Parameters
offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

Returns:E

the element at the offset

lvElementback to summary
protected final E lvElement(E[] buffer, long offset)

A volatile load (load + LoadLoad barrier) of an element from a given offset.

Parameters
buffer:E[]

this.buffer

offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

Returns:E

the element at the offset

Annotations
@SuppressWarnings:unchecked
soElementback to summary
protected final void soElement(long offset, E e)

An ordered store(store + StoreStore barrier) of an element to a given offset

Parameters
offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

e:E

an orderly kitty

soElementback to summary
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:E[]

this.buffer

offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

e:E

an orderly kitty

spElementback to summary
protected final void spElement(long offset, E e)

A plain store (no ordering/fences) of an element to a given offset

Parameters
offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

e:E

a kitty

spElementback to summary
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:E[]

this.buffer

offset:long

computed via ConcurrentCircularArrayQueue#calcElementOffset(long)

e:E

an orderly kitty