Package rx.internal.util.atomic
Class SpscAtomicArrayQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
rx.internal.util.atomic.AtomicReferenceArrayQueue<E>
rx.internal.util.atomic.SpscAtomicArrayQueue<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Queue<E>
A Single-Producer-Single-Consumer queue backed by a pre-allocated buffer.
This implementation is a mashup of the Fast Flow
algorithm with an optimization of the offer method taken from the BQueue algorithm (a variation on Fast
Flow), and adjusted to comply with Queue.offer semantics with regards to capacity.
For convenience the relevant papers are available in the resources folder:
2010 - Pisa - SPSC Queues on Shared Cache Multi-Core Systems.pdf
2012 - Junchang- BQueue- Efficient and Practical Queuing.pdf
This implementation is wait free.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AtomicLong(package private) final intprivate static final Integer(package private) final AtomicLong(package private) longFields inherited from class rx.internal.util.atomic.AtomicReferenceArrayQueue
buffer, mask -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEmpty()private longprivate longbooleanpeek()poll()intsize()private voidsoConsumerIndex(long newIndex) private voidsoProducerIndex(long newIndex) Methods inherited from class rx.internal.util.atomic.AtomicReferenceArrayQueue
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElement, svElementMethods inherited from class java.util.AbstractQueue
add, addAll, element, removeMethods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
MAX_LOOK_AHEAD_STEP
-
producerIndex
-
producerLookAhead
long producerLookAhead -
consumerIndex
-
lookAheadStep
final int lookAheadStep
-
-
Constructor Details
-
SpscAtomicArrayQueue
public SpscAtomicArrayQueue(int capacity)
-
-
Method Details
-
offer
-
poll
-
peek
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
soProducerIndex
private void soProducerIndex(long newIndex) -
soConsumerIndex
private void soConsumerIndex(long newIndex) -
lvConsumerIndex
private long lvConsumerIndex() -
lvProducerIndex
private long lvProducerIndex()
-