E -
public final class SpscAtomicArrayQueue<E> extends AbstractQueue<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 AtomicReferenceArray |
buffer
|
protected int |
mask
|
protected long |
producerLookAhead
|
| Constructor and Description |
|---|
SpscAtomicArrayQueue(int capacity)
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
calcElementOffset(long index)
|
protected int |
calcElementOffset(long index, int mask)
|
void |
clear()
|
Iterator |
iterator()
|
protected E |
lpElement(AtomicReferenceArray
|
protected E |
lpElement(int offset)
|
protected E |
lvElement(AtomicReferenceArray
|
protected E |
lvElement(int offset)
|
boolean |
offer(E e)
|
E |
peek()
|
E |
poll()
|
int |
size()
|
protected void |
soElement(AtomicReferenceArray
|
protected void |
soElement(int offset, E value)
|
protected void |
spElement(AtomicReferenceArray
|
protected void |
spElement(int offset, E value)
|
protected void |
svElement(AtomicReferenceArray
|
add, 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 producerLookAhead
protected final AtomicReferenceArray<E> buffer
protected final int mask
public boolean offer(E e)
public E poll()
public E peek()
public int size()
public Iterator<E> iterator()
public void clear()
protected final int calcElementOffset(long index,
int mask)protected final int calcElementOffset(long index)
protected final E lvElement(AtomicReferenceArray<E> buffer, int offset)
protected final E lpElement(AtomicReferenceArray<E> buffer, int offset)
protected final E lpElement(int offset)
protected final void spElement(AtomicReferenceArray<E> buffer, int offset, E value)
protected final void spElement(int offset,
E value)protected final void soElement(AtomicReferenceArray<E> buffer, int offset, E value)
protected final void soElement(int offset,
E value)protected final void svElement(AtomicReferenceArray<E> buffer, int offset, E value)
protected final E lvElement(int offset)