Additional top-level classes in compilation unit: MpmcAtomicArrayQueueL1Pad, MpmcAtomicArrayQueueProducerIndexField, MpmcAtomicArrayQueueL2Pad, MpmcAtomicArrayQueueConsumerIndexField, MpmcAtomicArrayQueueL3Pad.
Note
This class was automatically generated by io.netty5.util.internal.shaded.org.jctools.queues.atomic.JavaParsingAtomicArrayQueueGenerator
which can found in the jctools-build module. The original source file is MpmcArrayQueue.java.
A Multi-Producer-Multi-Consumer queue based on a io.. This
implies that any and all threads may call the offer/poll/peek methods and correctness is maintained.
This implementation follows patterns documented on the package level for False Sharing protection.
The algorithm for offer/poll is an adaptation of the one put forward by D. Vyukov (See here). The original
algorithm uses an array of structs which should offer nice locality properties but is sadly not possible in
Java (waiting on Value Types or similar). The alternative explored here utilizes 2 arrays, one for each
field of the struct. There is a further alternative in the experimental project which uses iteration phase
markers to achieve the same algo and is closer structurally to the original, but sadly does not perform as
well as this implementation.
Tradeoffs to keep in mind:
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| public static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | drain(MessagePassingQueue.
Implements io. |
| public int | drain(MessagePassingQueue.
Implements io. |
| public void | drain(MessagePassingQueue.
Implements io. |
| private int | |
| public int | fill(MessagePassingQueue.
Implements io. |
| public int | fill(MessagePassingQueue.
Implements io. |
| public void | fill(MessagePassingQueue.
Implements io. |
| private int | |
| private boolean | |
| public boolean | offer(final E
not e)null, will throw NPE if it isImplements io. Queue#offer(Object) interface.
|
| public E | peek()
Implements io. Queue#peek() interface.
|
| public E | poll()
Implements io. Queue#poll() interface.
|
| public boolean | relaxedOffer(E
not e)null, will throw NPE if it isImplements io. |
| public E | relaxedPeek()
Implements io. |
| public E | relaxedPoll()
Implements io. |
| lookAheadStep | back to summary |
|---|---|
| private final int lookAheadStep | |
| MAX_LOOK_AHEAD_STEP | back to summary |
|---|---|
| public static final int MAX_LOOK_AHEAD_STEP | |
| MpmcAtomicArrayQueue | back to summary |
|---|---|
| public MpmcAtomicArrayQueue(final int capacity) | |
| drain | back to summary |
|---|---|
| public int drain(MessagePassingQueue. Implements io. Doc from io. Remove up to limit elements from the queue and hand to consume. This should be semantically similar to:
There's no strong commitment to the queue being empty at the end of a drain. Called from a consumer thread subject to the restrictions appropriate to the implementation. Warning Explicit assumptions are made with regards to
| |
| drain | back to summary |
|---|---|
| public int drain(MessagePassingQueue. Implements io. Doc from io. Remove all available item from the queue and hand to consume. This should be semantically similar to:
M m;
while((m = relaxedPoll()) != null){
c.accept(m);
}
There's no strong commitment to the queue being empty at the end of a drain. Called from a
consumer thread subject to the restrictions appropriate to the implementation.Warning Explicit assumptions are made with regards to
| |
| drain | back to summary |
|---|---|
| public void drain(MessagePassingQueue. Implements io. Doc from io. Remove elements from the queue and hand to consume forever. Semantically similar to:
int idleCounter = 0;
while (exit.keepRunning()) {
E e = relaxedPoll();
if(e==null){
idleCounter = wait.idle(idleCounter);
continue;
}
idleCounter = 0;
c.accept(e);
}
Called from a consumer thread subject to the restrictions appropriate to the implementation. Warning Explicit assumptions are made with regards to
| |
| drainOneByOne | back to summary |
|---|---|
| private int drainOneByOne(MessagePassingQueue. | |
| fill | back to summary |
|---|---|
| public int fill(MessagePassingQueue. Implements io. Doc from io. Stuff the queue with up to limit elements from the supplier. Semantically similar to:
There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation Warning Explicit assumptions are made with regards to
| |
| fill | back to summary |
|---|---|
| public int fill(MessagePassingQueue. Implements io. Doc from io. Stuff the queue with elements from the supplier. Semantically similar to: while(relaxedOffer(s.get());There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation. Unbounded queues will fill up the queue with a fixed amount rather than fill up to oblivion Warning Explicit assumptions are made with regards to
| |
| fill | back to summary |
|---|---|
| public void fill(MessagePassingQueue. Implements io. Doc from io. Stuff the queue with elements from the supplier forever. Semantically similar to:
Called from a producer thread subject to the restrictions appropriate to the implementation. The main difference
being that implementors MUST assure room in the queue is available BEFORE calling Warning Explicit assumptions are made with regards to
| |
| fillOneByOne | back to summary |
|---|---|
| private int fillOneByOne(MessagePassingQueue. | |
| notAvailable | back to summary |
|---|---|
| private boolean notAvailable(long index, int mask, AtomicLongArray sBuffer, long expectedSeq) | |
| offer | back to summary |
|---|---|
| public boolean offer(final E e) Implements io. Doc from io. Called from a producer thread subject to the restrictions appropriate to the implementation and
according to the
| |
| peek | back to summary |
|---|---|
| public E peek() Implements io. Doc from io. Called from the consumer thread subject to the restrictions appropriate to the implementation and
according to the
| |
| poll | back to summary |
|---|---|
| public E poll() Implements io. Doc from io. Called from the consumer thread subject to the restrictions appropriate to the implementation and
according to the 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.
| |
| relaxedOffer | back to summary |
|---|---|
| public boolean relaxedOffer(E e) Implements io. Doc from io. Called from a producer thread subject to the restrictions appropriate to the implementation. As opposed
to
| |
| relaxedPeek | back to summary |
|---|---|
| public E relaxedPeek() Implements io. Doc from io. Called from the consumer thread subject to the restrictions appropriate to the implementation. As
opposed to
| |
| relaxedPoll | back to summary |
|---|---|
| public E relaxedPoll() Implements io. Doc from io. Called from the consumer thread subject to the restrictions appropriate to the implementation. As
opposed to
| |