E - public final class SpscArrayQueue<E>
extends java.util.concurrent.atomic.AtomicReferenceArray<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 int |
mask |
protected long |
producerLookAhead |
| Constructor and Description |
|---|
SpscArrayQueue(int capacity) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e) |
boolean |
addAll(java.util.Collection<? extends E> c) |
protected int |
calcElementOffset(long index) |
protected int |
calcElementOffset(long index,
int mask) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
E |
element() |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
protected E |
lpElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset) |
protected E |
lpElement(int offset) |
protected E |
lvElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset) |
protected E |
lvElement(int offset) |
boolean |
offer(E e) |
E |
peek() |
E |
poll() |
E |
remove() |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
protected void |
soElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value) |
protected void |
soElement(int offset,
E value) |
protected void |
spElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value) |
protected void |
spElement(int offset,
E value) |
protected void |
svElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
accumulateAndGet, compareAndSet, get, getAndAccumulate, getAndSet, getAndUpdate, lazySet, length, set, toString, updateAndGet, weakCompareAndSetclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic boolean offer(E e)
public E poll()
public E peek()
public boolean isEmpty()
public int size()
public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>public void clear()
clear in interface java.util.Collection<E>protected final int calcElementOffset(long index,
int mask)
protected final int calcElementOffset(long index)
protected final E lvElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset)
protected final E lpElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset)
protected final E lpElement(int offset)
protected final void spElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value)
protected final void spElement(int offset,
E value)
protected final void soElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value)
protected final void soElement(int offset,
E value)
protected final void svElement(java.util.concurrent.atomic.AtomicReferenceArray<E> buffer,
int offset,
E value)
protected final E lvElement(int offset)
public boolean add(E e)
add in interface java.util.Collection<E>add in interface java.util.Queue<E>public E remove()
remove in interface java.util.Queue<E>public E element()
element in interface java.util.Queue<E>public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<E>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>public <T> T[] toArray(T[] a)
toArray in interface java.util.Collection<E>public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<E>public boolean containsAll(java.util.Collection<?> c)
containsAll in interface java.util.Collection<E>public boolean addAll(java.util.Collection<? extends E> c)
addAll in interface java.util.Collection<E>public boolean removeAll(java.util.Collection<?> c)
removeAll in interface java.util.Collection<E>public boolean retainAll(java.util.Collection<?> c)
retainAll in interface java.util.Collection<E>