Class BaseMpscLinkedArrayQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueuePad1<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueProducerFields<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueuePad2<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueConsumerFields<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueuePad3<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueColdProducerFields<E>
com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueue<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Queue<E>
- Direct Known Subclasses:
MpscChunkedArrayQueueColdProducerFields
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
private static final Object
private static final long
private static final long
Fields inherited from class com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueColdProducerFields
producerBuffer, producerLimit, producerMask
Fields inherited from class com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueuePad3
p0, p1, p10, p11, p12, p13, p14, p15, p16, p17, p2, p3, p4, p5, p6, p7
Fields inherited from class com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueConsumerFields
consumerBuffer, consumerIndex, consumerMask
Fields inherited from class com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueuePad2
p01, p02, p03, p04, p05, p06, p07
Fields inherited from class com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueProducerFields
producerIndex
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> E[]
allocate
(int capacity) protected abstract long
availableInQueue
(long pIndex, long cIndex) abstract int
capacity()
private boolean
casProducerIndex
(long expect, long newValue) private boolean
casProducerLimit
(long expect, long newValue) long
long
protected abstract long
getCurrentBufferCapacity
(long mask) private E[]
getNextBuffer
(E[] buffer, long mask) protected abstract int
getNextBufferSize
(E[] buffer) final boolean
isEmpty()
iterator()
private long
private long
private long
private static long
modifiedCalcElementOffset
(long index, long mask) This method assumes index is actually (index << 1) because lower bit is used for resize.private long
newBufferAndOffset
(E[] nextBuffer, long index) private E
newBufferPeek
(E[] nextBuffer, long index) private E
newBufferPoll
(E[] nextBuffer, long index) private long
nextArrayOffset
(long mask) boolean
private int
offerSlowPath
(long mask, long pIndex, long producerLimit) We do not inline resize into this method because we do not resize on fill.peek()
poll()
boolean
relaxedOffer
(E e) private void
final int
size()
private void
soConsumerIndex
(long v) private void
soProducerIndex
(long v) private void
soProducerLimit
(long v) toString()
Methods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray
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
-
Field Details
-
P_INDEX_OFFSET
private static final long P_INDEX_OFFSET -
C_INDEX_OFFSET
private static final long C_INDEX_OFFSET -
P_LIMIT_OFFSET
private static final long P_LIMIT_OFFSET -
JUMP
-
-
Constructor Details
-
BaseMpscLinkedArrayQueue
public BaseMpscLinkedArrayQueue(int initialCapacity) - Parameters:
initialCapacity
- the queue initial capacity. If chunk size is fixed this will be the chunk size. Must be 2 or more.
-
-
Method Details
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
toString
- Overrides:
toString
in classAbstractCollection<E>
-
offer
-
offerSlowPath
private int offerSlowPath(long mask, long pIndex, long producerLimit) We do not inline resize into this method because we do not resize on fill. -
availableInQueue
protected abstract long availableInQueue(long pIndex, long cIndex) - Returns:
- available elements in queue * 2
-
modifiedCalcElementOffset
private static long modifiedCalcElementOffset(long index, long mask) This method assumes index is actually (index << 1) because lower bit is used for resize. This is compensated for by reducing the element shift. The computation is constant folded, so there's no cost. -
poll
This implementation is correct for single consumer thread use only.
-
peek
This implementation is correct for single consumer thread use only.
-
getNextBuffer
-
nextArrayOffset
private long nextArrayOffset(long mask) -
newBufferPoll
-
newBufferPeek
-
newBufferAndOffset
-
size
public final int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
lvProducerIndex
private long lvProducerIndex() -
lvConsumerIndex
private long lvConsumerIndex() -
soProducerIndex
private void soProducerIndex(long v) -
casProducerIndex
private boolean casProducerIndex(long expect, long newValue) -
soConsumerIndex
private void soConsumerIndex(long v) -
lvProducerLimit
private long lvProducerLimit() -
casProducerLimit
private boolean casProducerLimit(long expect, long newValue) -
soProducerLimit
private void soProducerLimit(long v) -
currentProducerIndex
public long currentProducerIndex() -
currentConsumerIndex
public long currentConsumerIndex() -
capacity
public abstract int capacity() -
relaxedOffer
-
relaxedPoll
-
relaxedPeek
-
resize
-
allocate
public static <E> E[] allocate(int capacity) -
getNextBufferSize
- Returns:
- next buffer size(inclusive of next array pointer)
-
getCurrentBufferCapacity
protected abstract long getCurrentBufferCapacity(long mask) - Returns:
- current buffer capacity for elements (excluding next pointer and jump entry) * 2
-