src/main/java/io/reactivex/internal/queue/SpscLinkedArrayQueue.java
@Override
    public boolean offer(T first, T second) {
        final AtomicReferenceArray<Object> buffer = producerBuffer;
        final long p = lvProducerIndex();
        final int m = producerMask;

        int pi = calcWrappedOffset(p + 2, m);

        if (null == lvElement(buffer, pi)) {
            pi = calcWrappedOffset(p, m);
            soElement(buffer, pi + 1, second);
            soElement(buffer, pi, first);
            soProducerIndex(p + 2);
        } else {
            final int capacity = buffer.length();
            final AtomicReferenceArray<Object> newBuffer = new AtomicReferenceArray<Object>(capacity);
            producerBuffer = newBuffer;

            pi = calcWrappedOffset(p, m);
            soElement(newBuffer, pi + 1, second); // StoreStore
            soElement(newBuffer, pi, first);
            soNext(buffer, newBuffer);

            soElement(buffer, pi, HAS_NEXT); // new buffer is visible after element is

            soProducerIndex(p + 2); // this ensures correctness on 32bit platforms
        }

        return true;
    }
@Override
    public boolean offer(T first, T second) {
        final AtomicReferenceArray<Object> buffer = producerBuffer;
        final long p = lvProducerIndex();
        final int m = producerMask;

        int pi = calcWrappedOffset(p + 2, m);

        if (null == lvElement(buffer, pi)) {
            pi = calcWrappedOffset(p, m);
            soElement(buffer, pi + 1, second);
            soElement(buffer, pi, first);
            soProducerIndex(p + 2);
        } else {
            final int capacity = buffer.length();
            final AtomicReferenceArray<Object> newBuffer = new AtomicReferenceArray<Object>(capacity);
            producerBuffer = newBuffer;

            pi = calcWrappedOffset(p, m);
            soElement(newBuffer, pi + 1, second); // StoreStore
            soElement(newBuffer, pi, first);
            soNext(buffer, newBuffer);

            soElement(buffer, pi, HAS_NEXT); // new buffer is visible after element is

            soProducerIndex(p + 2); // this ensures correctness on 32bit platforms
        }

        return true;
    }
@ Override public boolean offer ( T first , T second ) { final AtomicReferenceArray < Object > buffer = producerBuffer ; final long p = lvProducerIndex ( ) ; final int m = producerMask ; int pi = calcWrappedOffset ( p + 2 , m ) ; if ( null == lvElement ( buffer , pi ) ) { pi = calcWrappedOffset ( p , m ) ; soElement ( buffer , pi + 1 , second ) ; soElement ( buffer , pi , first ) ; soProducerIndex ( p + 2 ) ; } else { final int capacity = buffer . length ( ) ; final AtomicReferenceArray < Object > newBuffer = new AtomicReferenceArray < Object > ( capacity ) ; producerBuffer = newBuffer ; pi = calcWrappedOffset ( p , m ) ; soElement ( newBuffer , pi + 1 , second ) ; // StoreStore soElement ( newBuffer , pi , first ) ; soNext ( buffer , newBuffer ) ; soElement ( buffer , pi , HAS_NEXT ) ; // new buffer is visible after element is soProducerIndex ( p + 2 ) ; // this ensures correctness on 32bit platforms } return true ; }
Offer two elements at the same time.
<p>Don't use the regular offer() with this at all!
@param first the first value, not null
@param second the second value, not null
@return true if the queue accepted the two new values
Offer two elements at the same time . <p > Don t use the regular offer () with this at all!