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 int
private static final Integer
(package private) final AtomicLong
(package private) long
Fields inherited from class rx.internal.util.atomic.AtomicReferenceArrayQueue
buffer, mask
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
private long
private long
boolean
peek()
poll()
int
size()
private void
soConsumerIndex
(long newIndex) private void
soProducerIndex
(long newIndex) Methods inherited from class rx.internal.util.atomic.AtomicReferenceArrayQueue
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElement, svElement
Methods inherited from class java.util.AbstractQueue
add, addAll, element, remove
Methods inherited from class java.util.AbstractCollection
contains, containsAll, 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, 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:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
soProducerIndex
private void soProducerIndex(long newIndex) -
soConsumerIndex
private void soConsumerIndex(long newIndex) -
lvConsumerIndex
private long lvConsumerIndex() -
lvProducerIndex
private long lvProducerIndex()
-