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:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.Queue<E>
public final class SpscAtomicArrayQueue<E> extends AtomicReferenceArrayQueue<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
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicLongconsumerIndex(package private) intlookAheadStepprivate static java.lang.IntegerMAX_LOOK_AHEAD_STEP(package private) java.util.concurrent.atomic.AtomicLongproducerIndex(package private) longproducerLookAhead-
Fields inherited from class rx.internal.util.atomic.AtomicReferenceArrayQueue
buffer, mask
-
-
Constructor Summary
Constructors Constructor Description SpscAtomicArrayQueue(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisEmpty()private longlvConsumerIndex()private longlvProducerIndex()booleanoffer(E e)Epeek()Epoll()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, svElement
-
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
-
-
-
-
Field Detail
-
MAX_LOOK_AHEAD_STEP
private static final java.lang.Integer MAX_LOOK_AHEAD_STEP
-
producerIndex
final java.util.concurrent.atomic.AtomicLong producerIndex
-
producerLookAhead
long producerLookAhead
-
consumerIndex
final java.util.concurrent.atomic.AtomicLong consumerIndex
-
lookAheadStep
final int lookAheadStep
-
-
Method Detail
-
offer
public boolean offer(E e)
-
poll
public E poll()
-
peek
public E peek()
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
soProducerIndex
private void soProducerIndex(long newIndex)
-
soConsumerIndex
private void soConsumerIndex(long newIndex)
-
lvConsumerIndex
private long lvConsumerIndex()
-
lvProducerIndex
private long lvProducerIndex()
-
-