Package rx.internal.util.unsafe
Class MpscLinkedQueue<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- rx.internal.util.unsafe.BaseLinkedQueuePad0<E>
-
- rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef<E>
-
- rx.internal.util.unsafe.BaseLinkedQueuePad1<E>
-
- rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef<E>
-
- rx.internal.util.unsafe.BaseLinkedQueue<E>
-
- rx.internal.util.unsafe.MpscLinkedQueue<E>
-
- Type Parameters:
E
-
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
@SuppressAnimalSniffer public final class MpscLinkedQueue<E> extends BaseLinkedQueue<E>
This is a direct Java port 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:- Use inheritance to ensure no false sharing occurs between producer/consumer node reference fields.
- Use XCHG functionality to the best of the JDK ability (see differences in JDK7/8 impls).
-
-
Field Summary
-
Fields inherited from class rx.internal.util.unsafe.BaseLinkedQueue
p00, p01, p02, p03, p04, p05, p06, p07, p30, p31, p32, p33, p34, p35, p36, p37
-
Fields inherited from class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef
C_NODE_OFFSET, consumerNode
-
Fields inherited from class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef
P_NODE_OFFSET, producerNode
-
-
Constructor Summary
Constructors Constructor Description MpscLinkedQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
offer(E nextValue)
E
peek()
E
poll()
protected LinkedQueueNode<E>
xchgProducerNode(LinkedQueueNode<E> newVal)
-
Methods inherited from class rx.internal.util.unsafe.BaseLinkedQueue
isEmpty, iterator, size
-
Methods inherited from class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef
lpConsumerNode, lvConsumerNode, spConsumerNode
-
Methods inherited from class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef
lpProducerNode, lvProducerNode, spProducerNode
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
xchgProducerNode
protected LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> newVal)
-
offer
public boolean offer(E nextValue)
IMPLEMENTATION NOTES:
Offer is allowed from multiple threads.
Offer allocates a new node and:- Swaps it atomically with current producer node (only one producer 'wins')
- Sets the new node as the node following from the swapped producer node
- See Also:
MessagePassingQueue.offer(Object)
,Queue.offer(java.lang.Object)
-
poll
public E poll()
IMPLEMENTATION NOTES:
Poll is allowed from a SINGLE thread.
Poll reads the next node from the consumerNode and:- If it is null, the queue is assumed empty (though it might not be).
- If it is not null set it as the consumer node and return it's now evacuated value.
- See Also:
MessagePassingQueue.poll()
,Queue.poll()
-
peek
public E peek()
-
-