E -
public final class SpscArrayQueue<E> extends ConcurrentCircularArrayQueue<E>
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 |
|---|---|
protected static long |
C_INDEX_OFFSET
|
protected long |
consumerIndex
|
protected int |
lookAheadStep
|
protected static long |
P_INDEX_OFFSET
|
protected long |
producerIndex
|
protected long |
producerLookAhead
|
buffer, BUFFER_PAD, mask, SPARSE_SHIFT| Constructor and Description |
|---|
SpscArrayQueue(int capacity)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isEmpty()
This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
|
boolean |
offer(E e)
|
E |
peek()
|
E |
poll()
|
int |
size()
|
calcElementOffset, calcElementOffset, clear, iterator, lpElement, lpElement, lvElement, lvElement, soElement, soElement, spElement, spElementadd, addAll, element, removecontains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArrayprotected long consumerIndex
protected static final long C_INDEX_OFFSET
protected static final long P_INDEX_OFFSET
protected long producerIndex
protected long producerLookAhead
protected final int lookAheadStep
public boolean offer(E e)
This implementation is correct for single producer thread use only.
public E poll()
This implementation is correct for single consumer thread use only.
public E peek()
This implementation is correct for single consumer thread use only.
public int size()
public boolean isEmpty()