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:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
,QueueProgressIndicators
@SuppressAnimalSniffer public class SpscUnboundedArrayQueue<E> extends SpscUnboundedArrayQueueConsumerField<E> implements QueueProgressIndicators
-
-
Field Summary
Fields Modifier and Type Field Description private static long
C_INDEX_OFFSET
private static java.lang.Object
HAS_NEXT
(package private) static int
MAX_LOOK_AHEAD_STEP
private static long
P_INDEX_OFFSET
private static long
REF_ARRAY_BASE
private static int
REF_ELEMENT_SHIFT
-
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 Constructor Description SpscUnboundedArrayQueue(int bufferSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
adjustLookAheadStep(int capacity)
private static long
calcDirectOffset(long index)
private static long
calcWrappedOffset(long index, long mask)
long
currentConsumerIndex()
This method has no concurrent visibility semantics.long
currentProducerIndex()
This method has no concurrent visibility semantics.java.util.Iterator<E>
iterator()
private long
lvConsumerIndex()
private static <E> java.lang.Object
lvElement(E[] buffer, long offset)
private E[]
lvNext(E[] curr)
private long
lvProducerIndex()
private E
newBufferPeek(E[] nextBuffer, long index, long mask)
private E
newBufferPoll(E[] nextBuffer, long index, long mask)
boolean
offer(E e)
E
peek()
E
poll()
private void
resize(E[] oldBuffer, long currIndex, long offset, E e, long mask)
int
size()
private void
soConsumerIndex(long v)
private static void
soElement(java.lang.Object[] buffer, long offset, java.lang.Object e)
private void
soNext(E[] curr, E[] next)
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
-
-
-
-
Field Detail
-
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
private static final java.lang.Object HAS_NEXT
-
-
Method Detail
-
iterator
public final java.util.Iterator<E> iterator()
-
offer
public final boolean offer(E e)
This implementation is correct for single producer thread use only.
- Specified by:
offer
in interfacejava.util.Queue<E>
-
poll
public final E poll()
This implementation is correct for single consumer thread use only.
- Specified by:
poll
in interfacejava.util.Queue<E>
-
peek
public final E peek()
This implementation is correct for single consumer thread use only.
- Specified by:
peek
in interfacejava.util.Queue<E>
-
size
public final int size()
-
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
private static void soElement(java.lang.Object[] buffer, long offset, java.lang.Object e)
-
lvElement
private static <E> java.lang.Object lvElement(E[] buffer, long offset)
-
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
-
-