public class MpmcAtomicArrayQueue<E> extends AbstractQueue<E> implements QueueProgressIndicators
Modifier and Type | Field and Description |
---|---|
protected AtomicReferenceArray<E> |
buffer |
protected int |
mask |
protected AtomicLongArray |
sequenceBuffer |
Constructor and Description |
---|
MpmcAtomicArrayQueue(int capacity) |
Modifier and Type | Method and Description |
---|---|
protected int |
calcElementOffset(long index) |
protected int |
calcElementOffset(long index,
int mask) |
protected long |
calcSequenceOffset(long index) |
protected static int |
calcSequenceOffset(long index,
int mask) |
protected boolean |
casConsumerIndex(long expect,
long newValue) |
protected boolean |
casProducerIndex(long expect,
long newValue) |
void |
clear() |
long |
currentConsumerIndex()
This method has no concurrent visibility semantics.
|
long |
currentProducerIndex()
This method has no concurrent visibility semantics.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
protected E |
lpElement(AtomicReferenceArray<E> buffer,
int offset) |
protected E |
lpElement(int offset) |
protected long |
lvConsumerIndex() |
protected E |
lvElement(AtomicReferenceArray<E> buffer,
int offset) |
protected E |
lvElement(int offset) |
protected long |
lvProducerIndex() |
protected long |
lvSequence(AtomicLongArray buffer,
int offset) |
boolean |
offer(E e) |
E |
peek() |
E |
poll() |
int |
size() |
protected void |
soElement(AtomicReferenceArray<E> buffer,
int offset,
E value) |
protected void |
soElement(int offset,
E value) |
protected void |
soSequence(AtomicLongArray buffer,
int offset,
long e) |
protected void |
spElement(AtomicReferenceArray<E> buffer,
int offset,
E value) |
protected void |
spElement(int offset,
E value) |
protected void |
svElement(AtomicReferenceArray<E> buffer,
int offset,
E value) |
String |
toString() |
add, addAll, element, remove
contains, containsAll, remove, removeAll, retainAll, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
protected final AtomicLongArray sequenceBuffer
protected final AtomicReferenceArray<E> buffer
protected final int mask
public E poll()
Because return null indicates queue is empty we cannot simply rely on next element visibility for poll and must test producer index when next element is not visible.
public int size()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in class AbstractCollection<E>
public long currentProducerIndex()
QueueProgressIndicators
currentProducerIndex
in interface QueueProgressIndicators
public long currentConsumerIndex()
QueueProgressIndicators
currentConsumerIndex
in interface QueueProgressIndicators
protected final long lvProducerIndex()
protected final boolean casProducerIndex(long expect, long newValue)
protected final long lvConsumerIndex()
protected final boolean casConsumerIndex(long expect, long newValue)
protected final long calcSequenceOffset(long index)
protected static int calcSequenceOffset(long index, int mask)
protected final void soSequence(AtomicLongArray buffer, int offset, long e)
protected final long lvSequence(AtomicLongArray buffer, int offset)
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractQueue<E>
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)
Copyright © 2013–2017. All rights reserved.