Top Description Constructors Methods
io.netty.util.internal.shaded.org.jctools.queues

public Class SpscLinkedQueue<E>

extends BaseLinkedQueue<E>
Class Inheritance

This is a weakened version of the MPSC algorithm as presented on 1024 Cores by D. Vyukov. The original has been adapted to Java and it's quirks with regards to memory model and layout:
  1. Use inheritance to ensure no false sharing occurs between producer/consumer node reference fields.
  2. As this is an SPSC we have no need for XCHG, an ordered store is enough.
The queue is initialized with a stub node which is set to both the producer and consumer node references. From this point follow the notes on offer/poll.
Author
nitsanw

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
fill(MessagePassingQueue.Supplier<E> s)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Stuff the queue with elements from the supplier.
public int
fill(MessagePassingQueue.Supplier<E> s, int limit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Stuff the queue with up to limit elements from the supplier.
public void
public boolean
offer(final E
not null, will throw NPE if it is
e
)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.offer, java.util.Queue.offer.

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.
Inherited from io.netty.util.internal.shaded.org.jctools.queues.BaseLinkedQueue:
capacitydraindraindraingetSingleConsumerNodeValueisEmptyiteratornewNodenewNodepeekpollrelaxedOfferrelaxedPeekrelaxedPollsizespinWaitForNextNodetoString

Constructor Detail

SpscLinkedQueueback to summary
public SpscLinkedQueue()

Method Detail

fillback to summary
public int fill(MessagePassingQueue.Supplier<E> s)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

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 Supplier#get make sure you have read and understood these before using this method.

Returns:int

the number of offered elements

Annotations
@Override
fillback to summary
public int fill(MessagePassingQueue.Supplier<E> s, int limit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Stuff the queue with up to limit elements from the supplier. Semantically similar to:

for(int i=0; i < limit && relaxedOffer(s.get()); i++);

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 Supplier#get make sure you have read and understood these before using this method.

Returns:int

the number of offered elements

Annotations
@Override
fillback to summary
public void fill(MessagePassingQueue.Supplier<E> s, MessagePassingQueue.WaitStrategy wait, MessagePassingQueue.ExitCondition exit)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.fill.

Stuff the queue with elements from the supplier forever. Semantically similar to:


 int idleCounter = 0;
 while (exit.keepRunning()) {
     E e = s.get();
     while (!relaxedOffer(e)) {
         idleCounter = wait.idle(idleCounter);
         continue;
     }
     idleCounter = 0;
 }

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 Supplier#get

Warning

Explicit assumptions are made with regards to Supplier#get make sure you have read and understood these before using this method.

Annotations
@Override
offerback to summary
public boolean offer(final E e)

Implements io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.offer, java.util.Queue.offer.

Doc from io.netty.util.internal.shaded.org.jctools.queues.MessagePassingQueue.offer.

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.

IMPLEMENTATION NOTES:
Offer is allowed from a SINGLE thread.
Offer allocates a new node (holding the offered value) and:

  1. Sets the new node as the producerNode
  2. Sets that node as the lastProducerNode.next
From this follows that producerNode.next is always null and for all other nodes node.next is not null.
Parameters
e:E

not null, will throw NPE if it is

Returns:boolean

true if element was inserted into the queue, false iff full

Annotations
@Override
See Also
MessagePassingQueue#offer(Object), java.util.Queue#offer(java.lang.Object)