final E lvElement(int offset) { return get(offset); } }
@Nullable public final E poll() { final long index = consumerIndex.get(); final int offset = calcElementOffset(index); // local load of field to avoid repeated loads after volatile reads final E e = lvElement(offset);// LoadLoad if (null == e) { return null; } soConsumerIndex(index + 1); // ordered store -> atomic and ordered for size() soElement(offset, null);// StoreStore return e; }
public final boolean offer(E e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } // local load of field to avoid repeated loads after volatile reads final int mask = this.mask; final long index = producerIndex.get(); final int offset = calcElementOffset(index, mask); if (index >= producerLookAhead) { int step = lookAheadStep; if (null == lvElement(calcElementOffset(index + step, mask))) { // LoadLoad producerLookAhead = index + step; } else if (null != lvElement(offset)) { return false; } } soElement(offset, e); // StoreStore soProducerIndex(index + 1); // ordered store -> atomic and ordered for size() return true; }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
final void soElement(int offset, E value) { lazySet(offset, value); }
@Nullable public final E poll() { final long index = consumerIndex.get(); final int offset = calcElementOffset(index); // local load of field to avoid repeated loads after volatile reads final E e = lvElement(offset);// LoadLoad if (null == e) { return null; } soConsumerIndex(index + 1); // ordered store -> atomic and ordered for size() soElement(offset, null);// StoreStore return e; }
public final boolean offer(E e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } // local load of field to avoid repeated loads after volatile reads final int mask = this.mask; final long index = producerIndex.get(); final int offset = calcElementOffset(index, mask); if (index >= producerLookAhead) { int step = lookAheadStep; if (null == lvElement(calcElementOffset(index + step, mask))) { // LoadLoad producerLookAhead = index + step; } else if (null != lvElement(offset)) { return false; } } soElement(offset, e); // StoreStore soProducerIndex(index + 1); // ordered store -> atomic and ordered for size() return true; }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
final void soElement(int offset, E value) { lazySet(offset, value); }
@Nullable public final E poll() { final long index = consumerIndex.get(); final int offset = calcElementOffset(index); // local load of field to avoid repeated loads after volatile reads final E e = lvElement(offset);// LoadLoad if (null == e) { return null; } soConsumerIndex(index + 1); // ordered store -> atomic and ordered for size() soElement(offset, null);// StoreStore return e; }
public final boolean offer(E e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } // local load of field to avoid repeated loads after volatile reads final int mask = this.mask; final long index = producerIndex.get(); final int offset = calcElementOffset(index, mask); if (index >= producerLookAhead) { int step = lookAheadStep; if (null == lvElement(calcElementOffset(index + step, mask))) { // LoadLoad producerLookAhead = index + step; } else if (null != lvElement(offset)) { return false; } } soElement(offset, e); // StoreStore soProducerIndex(index + 1); // ordered store -> atomic and ordered for size() return true; }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
final void soElement(int offset, E value) { lazySet(offset, value); }
final E lvElement(int offset) { return get(offset); } }