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 | |
| pack-priv final int | |
| private static final Integer | |
| pack-priv final AtomicLong | |
| pack-priv long | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| pack-priv int | |
| public void | clear()
Implements io. |
| public boolean | isEmpty()
Implements io. |
| pack-priv E | |
| public boolean | offer(E
the value to enqueue, not null e)Implements io. |
| public boolean | offer(E
the first value to enqueue, not null v1, E the second value to enqueue, not null v2)Implements io. |
| public E | poll()
Implements io. |
| pack-priv void | |
| pack-priv void | |
| pack-priv void |
| consumerIndex | back to summary |
|---|---|
| pack-priv final AtomicLong consumerIndex | |
| lookAheadStep | back to summary |
|---|---|
| pack-priv final int lookAheadStep | |
| mask | back to summary |
|---|---|
| pack-priv final int mask | |
| 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 | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| SpscArrayQueue | back to summary |
|---|---|
| public SpscArrayQueue(int capacity) | |
| calcElementOffset | back to summary |
|---|---|
| pack-priv int calcElementOffset(long index, int mask) | |
| calcElementOffset | back to summary |
|---|---|
| pack-priv int calcElementOffset(long index) | |
| clear | back to summary |
|---|---|
| public void clear() Implements io. Doc from io. Removes all enqueued items from this queue.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements io. Doc from io. Returns true if the queue is empty.
Note however that due to potential fused functions in
| |
| lvElement | back to summary |
|---|---|
| pack-priv E lvElement(int offset) | |
| offer | back to summary |
|---|---|
| public boolean offer(E e) Implements io. Doc from io. Atomically enqueue a single.
| |
| offer | back to summary |
|---|---|
| public boolean offer(E v1, E v2) Implements io. Doc from io. Atomically enqueue two values.
| |
| poll | back to summary |
|---|---|
| public E poll() Implements io. Doc from io. Tries to dequeue a value (non-null) or returns null if the queue is empty.
If the producer uses | |
| soConsumerIndex | back to summary |
|---|---|
| pack-priv void soConsumerIndex(long newIndex) | |
| soElement | back to summary |
|---|---|
| pack-priv void soElement(int offset, E value) | |
| soProducerIndex | back to summary |
|---|---|
| pack-priv void soProducerIndex(long newIndex) | |