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 longC_INDEX_OFFSETprivate static java.lang.ObjectHAS_NEXT(package private) static intMAX_LOOK_AHEAD_STEPprivate static longP_INDEX_OFFSETprivate static longREF_ARRAY_BASEprivate static intREF_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 voidadjustLookAheadStep(int capacity)private static longcalcDirectOffset(long index)private static longcalcWrappedOffset(long index, long mask)longcurrentConsumerIndex()This method has no concurrent visibility semantics.longcurrentProducerIndex()This method has no concurrent visibility semantics.java.util.Iterator<E>iterator()private longlvConsumerIndex()private static <E> java.lang.ObjectlvElement(E[] buffer, long offset)private E[]lvNext(E[] curr)private longlvProducerIndex()private EnewBufferPeek(E[] nextBuffer, long index, long mask)private EnewBufferPoll(E[] nextBuffer, long index, long mask)booleanoffer(E e)Epeek()Epoll()private voidresize(E[] oldBuffer, long currIndex, long offset, E e, long mask)intsize()private voidsoConsumerIndex(long v)private static voidsoElement(java.lang.Object[] buffer, long offset, java.lang.Object e)private voidsoNext(E[] curr, E[] next)private voidsoProducerIndex(long v)private booleanwriteToQueue(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:
offerin interfacejava.util.Queue<E>
-
poll
public final E poll()
This implementation is correct for single consumer thread use only.
- Specified by:
pollin interfacejava.util.Queue<E>
-
peek
public final E peek()
This implementation is correct for single consumer thread use only.
- Specified by:
peekin 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:QueueProgressIndicatorsThis 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:
currentProducerIndexin interfaceQueueProgressIndicators- Returns:
- the current value of the producer progress index
-
currentConsumerIndex
public long currentConsumerIndex()
Description copied from interface:QueueProgressIndicatorsThis 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:
currentConsumerIndexin interfaceQueueProgressIndicators- Returns:
- the current value of the consumer progress index
-
-