Package rx.internal.util.unsafe
Class SpscUnboundedArrayQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueueProducerFields<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueueProducerColdFields<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueueL2Pad<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueueConsumerColdField<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueueConsumerField<E>
rx.internal.util.unsafe.SpscUnboundedArrayQueue<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Queue<E>
,QueueProgressIndicators
@SuppressAnimalSniffer
public class SpscUnboundedArrayQueue<E>
extends SpscUnboundedArrayQueueConsumerField<E>
implements QueueProgressIndicators
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
private static final Object
(package private) static final int
private static final long
private static final long
private static final int
Fields inherited from class rx.internal.util.unsafe.SpscUnboundedArrayQueueConsumerField
consumerIndex
Fields inherited from class rx.internal.util.unsafe.SpscUnboundedArrayQueueConsumerColdField
consumerBuffer, consumerMask
Fields inherited from class rx.internal.util.unsafe.SpscUnboundedArrayQueueL2Pad
p0, p1, p10, p11, p12, p2, p3, p4, p5, p6, p7, p8, p9
Fields inherited from class rx.internal.util.unsafe.SpscUnboundedArrayQueueProducerColdFields
producerBuffer, producerLookAhead, producerLookAheadStep, producerMask
Fields inherited from class rx.internal.util.unsafe.SpscUnboundedArrayQueueProducerFields
producerIndex
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
adjustLookAheadStep
(int capacity) private static long
calcDirectOffset
(long index) private static long
calcWrappedOffset
(long index, long mask) long
This method has no concurrent visibility semantics.long
This method has no concurrent visibility semantics.iterator()
private long
private static <E> Object
lvElement
(E[] buffer, long offset) private E[]
private long
private E
newBufferPeek
(E[] nextBuffer, long index, long mask) private E
newBufferPoll
(E[] nextBuffer, long index, long mask) final boolean
final E
peek()
final E
poll()
private void
final int
size()
private void
soConsumerIndex
(long v) private static void
private void
private void
soProducerIndex
(long v) private boolean
writeToQueue
(E[] buffer, E e, long index, long offset) Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, 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, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
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
-
-
Constructor Details
-
SpscUnboundedArrayQueue
public SpscUnboundedArrayQueue(int bufferSize)
-
-
Method Details
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
offer
This implementation is correct for single producer thread use only.
-
writeToQueue
-
resize
-
soNext
-
lvNext
-
poll
This implementation is correct for single consumer thread use only.
-
newBufferPoll
-
peek
This implementation is correct for single consumer thread use only.
-
newBufferPeek
-
size
public final int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<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
-
lvElement
-
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 interfaceQueueProgressIndicators
- 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 interfaceQueueProgressIndicators
- Returns:
- the current value of the consumer progress index
-