Package rx.internal.util.atomic
Class MpscLinkedAtomicQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
rx.internal.util.atomic.BaseLinkedAtomicQueue<E>
rx.internal.util.atomic.MpscLinkedAtomicQueue<E>
- Type Parameters:
E
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Queue<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 XCHG functionality provided by AtomicReference (which is better in JDK 8+).
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class rx.internal.util.atomic.BaseLinkedAtomicQueue
isEmpty, iterator, lpConsumerNode, lpProducerNode, lvConsumerNode, lvProducerNode, size, spConsumerNode, spProducerNode, xchgProducerNode
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
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
MpscLinkedAtomicQueue
public MpscLinkedAtomicQueue()
-
-
Method Details
-
offer
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:
-
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:
-
peek
-