@Test(expected = IllegalArgumentException.class) public void checkPositiveMustFailIfArgumentIsLessThanZero() { RangeUtil.checkPositive(-1, "var"); }
@Test(expected = IllegalArgumentException.class) public void checkPositiveMustFailIfArgumentIsZero() { RangeUtil.checkPositive(0, "var"); }
@Test public void checkPositiveMustPassIfArgumentIsGreaterThanZero() { final long n = 1; final long actual = RangeUtil.checkPositive(n, "var"); assertThat(actual, is(equalTo(n))); }
private void resize(long oldMask, E[] oldBuffer, long pIndex, E e) { int newBufferLength = getNextBufferSize(oldBuffer); final E[] newBuffer = allocate(newBufferLength); producerBuffer = newBuffer; final int newMask = (newBufferLength - 2) << 1; producerMask = newMask; final long offsetInOld = modifiedCalcElementOffset(pIndex, oldMask); final long offsetInNew = modifiedCalcElementOffset(pIndex, newMask); soElement(newBuffer, offsetInNew, e);// element in new array soElement(oldBuffer, nextArrayOffset(oldMask), newBuffer);// buffer linked // ASSERT code final long cIndex = lvConsumerIndex(); final long availableInQueue = availableInQueue(pIndex, cIndex); RangeUtil.checkPositive(availableInQueue, "availableInQueue"); // Invalidate racing CASs // We never set the limit beyond the bounds of a buffer soProducerLimit(pIndex + Math.min(newMask, availableInQueue)); // make resize visible to the other producers soProducerIndex(pIndex + 2); // INDEX visible before ELEMENT, consistent with consumer expectation // make resize visible to consumer soElement(oldBuffer, offsetInOld, JUMP); }
private void resize(long oldMask, AtomicReferenceArray<E> oldBuffer, long pIndex, E e) { int newBufferLength = getNextBufferSize(oldBuffer); final AtomicReferenceArray<E> newBuffer = allocate(newBufferLength); producerBuffer = newBuffer; final int newMask = (newBufferLength - 2) << 1; producerMask = newMask; final int offsetInOld = modifiedCalcElementOffset(pIndex, oldMask); final int offsetInNew = modifiedCalcElementOffset(pIndex, newMask); // element in new array soElement(newBuffer, offsetInNew, e); // buffer linked soElement(oldBuffer, nextArrayOffset(oldMask), newBuffer); // ASSERT code final long cIndex = lvConsumerIndex(); final long availableInQueue = availableInQueue(pIndex, cIndex); RangeUtil.checkPositive(availableInQueue, "availableInQueue"); // Invalidate racing CASs // We never set the limit beyond the bounds of a buffer soProducerLimit(pIndex + Math.min(newMask, availableInQueue)); // make resize visible to the other producers soProducerIndex(pIndex + 2); // INDEX visible before ELEMENT, consistent with consumer expectation // make resize visible to consumer soElement(oldBuffer, offsetInOld, JUMP); }
private void resize(long oldMask, E[] oldBuffer, long pIndex, E e) { int newBufferLength = getNextBufferSize(oldBuffer); final E[] newBuffer = allocate(newBufferLength); producerBuffer = newBuffer; final int newMask = (newBufferLength - 2) << 1; producerMask = newMask; final long offsetInOld = modifiedCalcElementOffset(pIndex, oldMask); final long offsetInNew = modifiedCalcElementOffset(pIndex, newMask); soElement(newBuffer, offsetInNew, e);// element in new array soElement(oldBuffer, nextArrayOffset(oldMask), newBuffer);// buffer linked // ASSERT code final long cIndex = lvConsumerIndex(); final long availableInQueue = availableInQueue(pIndex, cIndex); RangeUtil.checkPositive(availableInQueue, "availableInQueue"); // Invalidate racing CASs // We never set the limit beyond the bounds of a buffer soProducerLimit(pIndex + Math.min(newMask, availableInQueue)); // make resize visible to the other producers soProducerIndex(pIndex + 2); // INDEX visible before ELEMENT, consistent with consumer expectation // make resize visible to consumer soElement(oldBuffer, offsetInOld, JUMP); }
private void resize(long oldMask, AtomicReferenceArray<E> oldBuffer, long pIndex, E e) { int newBufferLength = getNextBufferSize(oldBuffer); final AtomicReferenceArray<E> newBuffer = allocate(newBufferLength); producerBuffer = newBuffer; final int newMask = (newBufferLength - 2) << 1; producerMask = newMask; final int offsetInOld = modifiedCalcElementOffset(pIndex, oldMask); final int offsetInNew = modifiedCalcElementOffset(pIndex, newMask); // element in new array soElement(newBuffer, offsetInNew, e); // buffer linked soElement(oldBuffer, nextArrayOffset(oldMask), newBuffer); // ASSERT code final long cIndex = lvConsumerIndex(); final long availableInQueue = availableInQueue(pIndex, cIndex); RangeUtil.checkPositive(availableInQueue, "availableInQueue"); // Invalidate racing CASs // We never set the limit beyond the bounds of a buffer soProducerLimit(pIndex + Math.min(newMask, availableInQueue)); // make resize visible to the other producers soProducerIndex(pIndex + 2); // INDEX visible before ELEMENT, consistent with consumer expectation // make resize visible to consumer soElement(oldBuffer, offsetInOld, JUMP); }