public Object poll(long timeout) throws InterruptedException {

        Object old = null;

        // D220640: Next two lines pulled out of synchronization block:

        // E2E optimized long start = (timeout <= 0) ? 0 :
        // System.currentTimeMillis();
        long start = (timeout <= 0) ? 0 : -1;
        long waitTime = timeout;

        // D312598 - begin
        while (true) {
            synchronized (this) {
                if (numberOfUsedSlots.get() > 0) {
                    old = extract();
                    numberOfUsedSlots.getAndDecrement();
                }
                if (old != null) {
                    // PK77809 Decrement the number of waiting threads since we will be
                    // returning a work item to a waiting thread to execute.
                    waitingThreads--;
                }
            }

            if (old != null) {
                notifyPut_();
                return old;
            }

            if (start == -1)
                start = System.currentTimeMillis();

            int spinctr = SPINS_TAKE_;
            while (numberOfUsedSlots.get() <= 0) {
                if (waitTime <= 0) {
                    return null;
                }
                // busy wait
                if (spinctr > 0) {
                    if (YIELD_TAKE_)
                        Thread.yield();
                    spinctr--;
                } else {
                    // block on lock
                    waitGet_(waitTime);
                }
                waitTime = timeout - (System.currentTimeMillis() - start);
            }
        }
        // D312598 - end

    }
public Object poll ( long timeout ) throws InterruptedException { Object old = null ; long start = ( timeout <= 0 ) ? 0 : - 1 ; long waitTime = timeout ; while ( true ) { synchronized ( this ) { if ( numberOfUsedSlots . get ( ) > 0 ) { old = extract ( ) ; numberOfUsedSlots . getAndDecrement ( ) ; } if ( old != null ) { waitingThreads -- ; } } if ( old != null ) { notifyPut_ ( ) ; return old ; } if ( start == - 1 ) start = System . currentTimeMillis ( ) ; int spinctr = SPINS_TAKE_ ; while ( numberOfUsedSlots . get ( ) <= 0 ) { if ( waitTime <= 0 ) { return null ; } if ( spinctr > 0 ) { if ( YIELD_TAKE_ ) Thread . yield ( ) ; spinctr -- ; } else { waitGet_ ( waitTime ) ; } waitTime = timeout - ( System . currentTimeMillis ( ) - start ) ; } } }
Removes an object from the buffer. If the buffer is empty, the call blocks
for up to
a specified amount of time before it gives up.

@param timeout
-
the amount of time (in milliseconds), that the caller is willing
to wait
in the event of an empty buffer.