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 longprivate static final Objectprivate static final longprivate static final longFields inherited from class BaseMpscLinkedArrayQueueColdProducerFields
producerBuffer, producerLimit, producerMaskFields inherited from class BaseMpscLinkedArrayQueuePad3
p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015, p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031, p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047, p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063, p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079, p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095, p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119Fields inherited from class BaseMpscLinkedArrayQueueConsumerFields
consumerBuffer, consumerIndex, consumerMaskFields inherited from class BaseMpscLinkedArrayQueueProducerFields
producerIndex -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> E[]allocate(int capacity) protected abstract longavailableInQueue(long pIndex, long cIndex) abstract intcapacity()private booleancasProducerIndex(long expect, long newValue) private booleancasProducerLimit(long expect, long newValue) longlongprotected abstract longgetCurrentBufferCapacity(long mask) private E[]getNextBuffer(E[] buffer, long mask) protected abstract intgetNextBufferSize(E[] buffer) final booleanisEmpty()iterator()private longprivate longprivate longprivate static longmodifiedCalcElementOffset(long index, long mask) This method assumes index is actually (index invalid input: '<'invalid input: '<' 1) because lower bit is used for resize.private longnewBufferAndOffset(E[] nextBuffer, long index) private EnewBufferPeek(E[] nextBuffer, long index) private EnewBufferPoll(E[] nextBuffer, long index) private static longnextArrayOffset(long mask) booleanprivate intofferSlowPath(long mask, long pIndex, long producerLimit) We do not inline resize into this method because we do not resize on fill.peek()poll()booleanrelaxedOffer(E e) private voidfinal intsize()private voidsoConsumerIndex(long v) private voidsoProducerIndex(long v) private voidsoProducerLimit(long v) toString()Methods inherited from class AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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
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
-
toString
- Overrides:
toStringin 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 invalid input: '<'invalid input: '<' 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 static long nextArrayOffset(long mask) -
newBufferPoll
-
newBufferPeek
-
newBufferAndOffset
-
size
public final int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin 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
-