E
- public final class SpscAtomicArrayQueue<E> extends AtomicReferenceArrayQueue<E> implements QueueProgressIndicators
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.
Modifier and Type | Field and Description |
---|---|
(package private) java.util.concurrent.atomic.AtomicLong |
consumerIndex |
(package private) int |
lookAheadStep |
private static java.lang.Integer |
MAX_LOOK_AHEAD_STEP |
(package private) java.util.concurrent.atomic.AtomicLong |
producerIndex |
protected long |
producerLookAhead |
buffer, mask
Constructor and Description |
---|
SpscAtomicArrayQueue(int capacity) |
Modifier and Type | Method and Description |
---|---|
long |
currentConsumerIndex()
This method has no concurrent visibility semantics.
|
long |
currentProducerIndex()
This method has no concurrent visibility semantics.
|
private long |
lvConsumerIndex() |
private long |
lvProducerIndex() |
boolean |
offer(E e) |
E |
peek() |
E |
poll() |
int |
size() |
private void |
soConsumerIndex(long newIndex) |
private void |
soProducerIndex(long newIndex) |
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElement, svElement
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
private static final java.lang.Integer MAX_LOOK_AHEAD_STEP
final java.util.concurrent.atomic.AtomicLong producerIndex
protected long producerLookAhead
final java.util.concurrent.atomic.AtomicLong consumerIndex
final int lookAheadStep
public int size()
public long currentProducerIndex()
QueueProgressIndicators
currentProducerIndex
in interface QueueProgressIndicators
public long currentConsumerIndex()
QueueProgressIndicators
currentConsumerIndex
in interface QueueProgressIndicators
private void soProducerIndex(long newIndex)
private void soConsumerIndex(long newIndex)
private long lvConsumerIndex()
private long lvProducerIndex()