@Override
    public int drain(Consumer<E> c, int limit)
    {
        final long mask = this.mask;
        final AtomicReferenceArray<E> buffer = this.buffer;
        for (int i = 0; i < limit; i++)
        {
            final long consumerPosition = lvConsumerPosition();
            final int offset = calcElementOffset(consumerPosition, mask);
            E e;
            if ((e = buffer.get(offset)) != null)
            {
                //can be used a memory_order_relaxed set here, because the consumer position write release the buffer value
                buffer.lazySet(offset, null);
                //consumer position allows the producers to move the claim limit (aka reduce backpressure)
                //hence can be set only after the buffer slot release
                soConsumerPosition(consumerPosition + 1);
                c.accept(e);
            }
            else
            {
                return i;
            }
        }
        return limit;
    }
NOTE: This class was automatically generated by org.jctools.queues.atomic.JavaParsingAtomicArrayQueueGenerator
which can found in the jctools-build module. The original source file is MpscArrayQueue.java.
jctools-experimental/src/main/java/org/jctools/queues/atomic/MpscRelaxedAtomicArrayQueue.java