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 |
|---|---|
| pack-priv final AtomicLong | |
| pack-priv final int | |
| private static final Integer | |
| pack-priv final AtomicLong | |
| pack-priv long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isEmpty()
Overrides java. Implements java. true if this collection contains no elements.
|
| private long | |
| private long | |
| public boolean | offer(E
the element to add e)Implements java. |
| public E | peek()
Implements java. null if this queue is empty.
|
| public E | poll()
Implements java. null if this queue is empty.
|
| public int | size()
Implements abstract java. Implements java. |
| private void | |
| private void |
| consumerIndex | back to summary |
|---|---|
| pack-priv final AtomicLong consumerIndex | |
| lookAheadStep | back to summary |
|---|---|
| pack-priv final int lookAheadStep | |
| MAX_LOOK_AHEAD_STEP | back to summary |
|---|---|
| private static final Integer MAX_LOOK_AHEAD_STEP | |
| producerIndex | back to summary |
|---|---|
| pack-priv final AtomicLong producerIndex | |
| producerLookAhead | back to summary |
|---|---|
| pack-priv long producerLookAhead | |
| SpscAtomicArrayQueue | back to summary |
|---|---|
| public SpscAtomicArrayQueue(int capacity) | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Overrides java. Implements java. Doc from java. Returns
| |
| lvConsumerIndex | back to summary |
|---|---|
| private long lvConsumerIndex() | |
| lvProducerIndex | back to summary |
|---|---|
| private long lvProducerIndex() | |
| offer | back to summary |
|---|---|
| public boolean offer(E e) Implements java. Doc from java. Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
When using a capacity-restricted queue, this method is generally
preferable to
| |
| peek | back to summary |
|---|---|
| public E peek() Implements java. Doc from java. Retrieves, but does not remove, the head of this queue,
or returns
| |
| poll | back to summary |
|---|---|
| public E poll() Implements java. Doc from java. Retrieves and removes the head of this queue,
or returns
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this collection. If this collection
contains more than
| |
| soConsumerIndex | back to summary |
|---|---|
| private void soConsumerIndex(long newIndex) | |
| soProducerIndex | back to summary |
|---|---|
| private void soProducerIndex(long newIndex) | |