private boolean attempt(long nanos) throws InterruptedException { if (state != 0) return true; if (nanos <= 0) { state = CANCEL; notify(); return false; } long deadline = Utils.nanoTime() + nanos; while (true) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (state != 0) return true; nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { state = CANCEL; notify(); return false; } } }
private boolean attempt(long nanos) throws InterruptedException { if (state != 0) return true; if (nanos <= 0) { state = CANCEL; notify(); return false; } long deadline = Utils.nanoTime() + nanos; while (true) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (state != 0) return true; nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { state = CANCEL; notify(); return false; } } }
private boolean attempt(long nanos) throws InterruptedException { if (state != 0) return true; if (nanos <= 0) { state = CANCEL; notify(); return false; } long deadline = Utils.nanoTime() + nanos; while (true) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (state != 0) return true; nanos = deadline - Utils.nanoTime(); if (nanos <= 0) { state = CANCEL; notify(); return false; } } }
long deadline = Utils.nanoTime() + nanos; for (; ; ) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (permits_ > 0) { --permits_;
long deadline = Utils.nanoTime() + nanos; for (; ; ) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (permits_ > 0) { --permits_;
long deadline = Utils.nanoTime() + nanos; for (; ; ) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (permits_ > 0) { --permits_;
try { for (; ; ) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (!waiting) // definitely signalled return true;
/** * Retrieves and removes the head of this queue, waiting if necessary * until an element with an expired delay is available on this queue. * * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ public Object take() throws InterruptedException { synchronized (lock) { for (;;) { Object first = q.peek(); if (first == null) { lock.wait(); } else { long delay = ((Delayed)first).getDelay(TimeUnit.NANOSECONDS); if (delay > 0) { TimeUnit.NANOSECONDS.timedWait(lock, delay); } else { Object x = q.poll(); assert x != null; if (q.size() != 0) lock.notifyAll(); // wake up other takers return x; } } } } }
/** * Retrieves and removes the head of this queue, waiting if necessary * until an element with an expired delay is available on this queue. * * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ public Object take() throws InterruptedException { synchronized (lock) { for (;;) { Object first = q.peek(); if (first == null) { lock.wait(); } else { long delay = ((Delayed)first).getDelay(TimeUnit.NANOSECONDS); if (delay > 0) { TimeUnit.NANOSECONDS.timedWait(lock, delay); } else { Object x = q.poll(); assert x != null; if (q.size() != 0) lock.notifyAll(); // wake up other takers return x; } } } } }
/** * Retrieves and removes the head of this queue, waiting if necessary * until an element with an expired delay is available on this queue. * * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ public Object take() throws InterruptedException { synchronized (lock) { for (;;) { Object first = q.peek(); if (first == null) { lock.wait(); } else { long delay = ((Delayed)first).getDelay(TimeUnit.NANOSECONDS); if (delay > 0) { TimeUnit.NANOSECONDS.timedWait(lock, delay); } else { Object x = q.poll(); //assert x != null; if (q.size() != 0) lock.notifyAll(); // wake up other takers return x; } } } } }
/** * Waits for the task to complete for timeout nanoseconds or throw * TimeoutException if still not completed after that * PRE: lock owned */ private void waitFor(long nanos) throws InterruptedException, TimeoutException { if (nanos < 0) throw new IllegalArgumentException(); if (isDone()) return; long deadline = Utils.nanoTime() + nanos; while (nanos > 0) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (isDone()) return; nanos = deadline - Utils.nanoTime(); } throw new TimeoutException(); }
if (nanos > 0) { long start = Utils.nanoTime(); TimeUnit.NANOSECONDS.timedWait(this, nanos);
if (nanos > 0) { long start = Utils.nanoTime(); TimeUnit.NANOSECONDS.timedWait(this, nanos);
return false; try { TimeUnit.NANOSECONDS.timedWait(putLock, nanos); nanos = deadline - Utils.nanoTime(); } catch (InterruptedException ie) {
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; }
/** * Waits for the task to complete for timeout nanoseconds or throw * TimeoutException if still not completed after that * PRE: lock owned */ private void waitFor(long nanos) throws InterruptedException, TimeoutException { if (nanos < 0) throw new IllegalArgumentException(); if (isDone()) return; long deadline = Utils.nanoTime() + nanos; while (nanos > 0) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (isDone()) return; nanos = deadline - Utils.nanoTime(); } throw new TimeoutException(); }
/** * Waits for the task to complete for timeout nanoseconds or throw * TimeoutException if still not completed after that * PRE: lock owned */ private void waitFor(long nanos) throws InterruptedException, TimeoutException { if (nanos < 0) throw new IllegalArgumentException(); if (isDone()) return; long deadline = Utils.nanoTime() + nanos; while (nanos > 0) { TimeUnit.NANOSECONDS.timedWait(this, nanos); if (isDone()) return; nanos = deadline - Utils.nanoTime(); } throw new TimeoutException(); }
if (nanos > 0) { long start = Utils.nanoTime(); TimeUnit.NANOSECONDS.timedWait(this, nanos);
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; }