public Object poll() { if (count == 0) return null; Object x = null; int c = -1; synchronized (takeLock) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } } if (c == capacity) signalNotFull(); return x; }
public Object poll() { if (count == 0) return null; Object x = null; int c = -1; synchronized (takeLock) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } } if (c == capacity) signalNotFull(); return x; }
public Object poll() { if (count == 0) return null; Object x = null; int c = -1; synchronized (takeLock) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } } if (c == capacity) signalNotFull(); return x; }
public Object take() throws InterruptedException { Object x; int c = -1; synchronized (takeLock) { try { while (count == 0) takeLock.wait(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } if (c == capacity) signalNotFull(); return x; }
public Object take() throws InterruptedException { Object x; int c = -1; synchronized (takeLock) { try { while (count == 0) takeLock.wait(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } if (c == capacity) signalNotFull(); return x; }
public Object take() throws InterruptedException { Object x; int c = -1; synchronized (takeLock) { try { while (count == 0) takeLock.wait(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); } if (c == capacity) signalNotFull(); return x; }
public Object poll(long timeout, TimeUnit unit) throws InterruptedException { Object x = null; int c = -1; long nanos = unit.toNanos(timeout); synchronized (takeLock) { long deadline = Utils.nanoTime() + nanos; for (;;) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); break; } if (nanos <= 0) return null; try { TimeUnit.NANOSECONDS.timedWait(takeLock, nanos); nanos = deadline - Utils.nanoTime(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } } } if (c == capacity) signalNotFull(); return x; }
public Object poll(long timeout, TimeUnit unit) throws InterruptedException { Object x = null; int c = -1; long nanos = unit.toNanos(timeout); synchronized (takeLock) { long deadline = Utils.nanoTime() + nanos; for (;;) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); break; } if (nanos <= 0) return null; try { TimeUnit.NANOSECONDS.timedWait(takeLock, nanos); nanos = deadline - Utils.nanoTime(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } } } if (c == capacity) signalNotFull(); return x; }
public Object poll(long timeout, TimeUnit unit) throws InterruptedException { Object x = null; int c = -1; long nanos = unit.toNanos(timeout); synchronized (takeLock) { long deadline = Utils.nanoTime() + nanos; for (;;) { if (count > 0) { x = extract(); synchronized (this) { c = count--; } if (c > 1) takeLock.notify(); break; } if (nanos <= 0) return null; try { TimeUnit.NANOSECONDS.timedWait(takeLock, nanos); nanos = deadline - Utils.nanoTime(); } catch (InterruptedException ie) { takeLock.notify(); // propagate to a non-interrupted thread throw ie; } } } if (c == capacity) signalNotFull(); return x; }