E
- public class SpscArrayQueue<E> extends ConcurrentCircularArrayQueue<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 |
---|---|
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, mask, REF_BUFFER_PAD, SPARSE_SHIFT
Constructor and Description |
---|
SpscArrayQueue(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.
|
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, spElement
add, addAll, element, remove
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
protected 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()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public long currentProducerIndex()
QueueProgressIndicators
currentProducerIndex
in interface QueueProgressIndicators
public long currentConsumerIndex()
QueueProgressIndicators
currentConsumerIndex
in interface QueueProgressIndicators
public boolean isEmpty()
Copyright © 2013–2015. All rights reserved.