public MpmcArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); lookAheadStep = Math.max(2, Math.min(capacity() / 4, MAX_LOOK_AHEAD_STEP)); }
public MpmcAtomicArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); lookAheadStep = Math.max(2, Math.min(capacity() / 4, MAX_LOOK_AHEAD_STEP)); }
public SpscChunkedArrayQueue(int chunkSize, int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array E[] buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; producerBufferLimit = mask - 1; // we know it's all empty to start with producerQueueLimit = maxQueueCapacity; }
public SpscChunkedAtomicArrayQueue(int chunkSize, int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array AtomicReferenceArray<E> buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with producerBufferLimit = mask - 1; producerQueueLimit = maxQueueCapacity; }
@Test(expected = IllegalArgumentException.class) public void checkGreaterThanOrEqualMustFailIfArgumentIsLessThanExpected() { RangeUtil.checkGreaterThanOrEqual(0, 1, "var"); }
public SpscGrowableArrayQueue(final int chunkSize, final int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array E[] buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; producerBufferLimit = mask - 1; // we know it's all empty to start with adjustLookAheadStep(chunkCapacity); }
public SpscGrowableAtomicArrayQueue(final int chunkSize, final int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array AtomicReferenceArray<E> buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with producerBufferLimit = mask - 1; adjustLookAheadStep(chunkCapacity); }
@Test public void checkGreaterThanOrEqualMustPassIfArgumentIsGreaterThanExpected() { final int n = 1; final int actual = RangeUtil.checkGreaterThanOrEqual(n, 0, "var"); assertThat(actual, is(equalTo(n))); } }
MpscChunkedAtomicArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }
/** * @param initialCapacity the queue initial capacity. If chunk size is fixed this will be the chunk size. * Must be 2 or more. */ public BaseMpscLinkedAtomicArrayQueue(final int initialCapacity) { RangeUtil.checkGreaterThanOrEqual(initialCapacity, 2, "initialCapacity"); int p2capacity = Pow2.roundToPowerOfTwo(initialCapacity); // leave lower bit of mask clear long mask = (p2capacity - 1) << 1; // need extra element to point at next array AtomicReferenceArray<E> buffer = allocate(p2capacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with soProducerLimit(mask); }
@Test public void checkGreaterThanOrEqualMustPassIfArgumentIsEqualToExpected() { final int n = 1; final int actual = RangeUtil.checkGreaterThanOrEqual(n, 1, "var"); assertThat(actual, is(equalTo(n))); }
/** * @param initialCapacity the queue initial capacity. If chunk size is fixed this will be the chunk size. * Must be 2 or more. */ public BaseMpscLinkedArrayQueue(final int initialCapacity) { RangeUtil.checkGreaterThanOrEqual(initialCapacity, 2, "initialCapacity"); int p2capacity = Pow2.roundToPowerOfTwo(initialCapacity); // leave lower bit of mask clear long mask = (p2capacity - 1) << 1; // need extra element to point at next array E[] buffer = allocate(p2capacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; soProducerLimit(mask); // we know it's all empty to start with }
MpscChunkedArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }
@SuppressWarnings("unchecked") MpscCompoundQueueColdFields(int capacity, int queueParallelism) { parallelQueues = isPowerOfTwo(queueParallelism) ? queueParallelism : roundToPowerOfTwo(queueParallelism) / 2; parallelQueuesMask = parallelQueues - 1; queues = new MpscArrayQueue[parallelQueues]; int fullCapacity = roundToPowerOfTwo(capacity); RangeUtil.checkGreaterThanOrEqual(fullCapacity, parallelQueues, "fullCapacity"); for (int i = 0; i < parallelQueues; i++) { queues[i] = new MpscArrayQueue<E>(fullCapacity / parallelQueues); } } }
public MpscBlockingConsumerArrayQueue(final int capacity) { // leave lower bit of mask clear super((long) ((Pow2.roundToPowerOfTwo(capacity) - 1) << 1), (E[])allocate(Pow2.roundToPowerOfTwo(capacity))); RangeUtil.checkGreaterThanOrEqual(capacity, 1, "capacity"); soProducerLimit((long) ((Pow2.roundToPowerOfTwo(capacity) - 1) << 1)); // we know it's all empty to start with }
public MpscRelaxedArrayQueue(int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity"); capacity = Pow2.roundToPowerOfTwo(capacity * 2); this.buffer = CircularArrayOffsetCalculator.allocate(capacity); this.soConsumerPosition(0); this.soActiveCycleId(0); this.mask = capacity - 1; this.cycleLength = capacity / 2; this.soProducerLimit(this.cycleLength); this.cycleLengthLog2 = Integer.numberOfTrailingZeros(this.cycleLength); // it allows at least 1L << 28 = 268435456 overclaims of the position within a cycle while waiting a rotation // to complete: this would help to increase the cycleId domain with small capacity this.cycleIdBitShift = Math.min(32, Integer.numberOfTrailingZeros(Pow2.roundToPowerOfTwo(this.cycleLength + (1 << 28)))); // it is the max position on cycle too this.positionWithinCycleMask = (int) ((1L << this.cycleIdBitShift) - 1); this.maxCycleId = (1L << (Long.SIZE - this.cycleIdBitShift)) - 1; this.soProducerCycleClaim(0, 0); this.soProducerCycleClaim(1, this.cycleLength + 1); }
public MpmcArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); }
public MpmcAtomicArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); }
MpscChunkedAtomicArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }
MpscChunkedArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }