/** * Align a value to the next multiple up of alignment. If the value equals an alignment multiple then it * is returned unchanged. * * @param value to be aligned up. * @param alignment to be used, must be a power of 2. * @return the value aligned to the next boundary. */ public static long align(final long value, final int alignment) { if (!isPowerOfTwo(alignment)) { throw new IllegalArgumentException("alignment must be a power of 2:" + alignment); } return (value + (alignment - 1)) & ~(alignment - 1); } }
@SuppressWarnings("unchecked") protected BQueueColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[this.capacity + BUFFER_PAD * 2]; } }
@SuppressWarnings("unchecked") public MpmcConcurrentQueueSMBuffer(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; // pad data on either end with some empty slots. buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; }
@SuppressWarnings("unchecked") InlinedRingBufferColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; } }
@SuppressWarnings("unchecked") FloatingCaqColdFields(int capacity) { if (Pow2.isPowerOfTwo(capacity)) { this.capacity = capacity; } else { this.capacity = Pow2.roundToPowerOfTwo(capacity); } mask = this.capacity - 1; buffer = (E[]) new Object[(this.capacity << SPARSE_SHIFT) + BUFFER_PAD * 2]; } }
@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); } } }
/** * Align a value to the next multiple up of alignment. If the value equals an alignment multiple then it * is returned unchanged. * * @param value to be aligned up. * @param alignment to be used, must be a power of 2. * @return the value aligned to the next boundary. */ public static long align(final long value, final int alignment) { if (!isPowerOfTwo(alignment)) { throw new IllegalArgumentException("alignment must be a power of 2:" + alignment); } return (value + (alignment - 1)) & ~(alignment - 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); } } }