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, svElementcontains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitprivate 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()
QueueProgressIndicatorscurrentProducerIndex in interface QueueProgressIndicatorspublic long currentConsumerIndex()
QueueProgressIndicatorscurrentConsumerIndex in interface QueueProgressIndicatorsprivate void soProducerIndex(long newIndex)
private void soConsumerIndex(long newIndex)
private long lvConsumerIndex()
private long lvProducerIndex()