/** * Returns current nanosecond time. */ final long now() { return Utils.nanoTime(); }
/** * Returns current nanosecond time. */ final long now() { return Utils.nanoTime(); }
/** * Returns current nanosecond time. */ final long now() { return Utils.nanoTime(); }
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; } } }
/** * 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(); }
/** * 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(); }
/** * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ public boolean offerLast(Object e, long timeout, TimeUnit unit) throws InterruptedException { if (e == null) throw new NullPointerException(); long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { if (linkLast(e)) return true; if (nanos <= 0) return false; notFull.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollLast(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkLast(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
/** * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ public boolean offerLast(Object e, long timeout, TimeUnit unit) throws InterruptedException { if (e == null) throw new NullPointerException(); long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { if (linkLast(e)) return true; if (nanos <= 0) return false; notFull.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollLast(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkLast(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollLast(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkLast(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollFirst(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkFirst(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollFirst(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkFirst(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public Object pollFirst(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; lock.lockInterruptibly(); try { for (;;) { Object x = unlinkFirst(); if (x != null) return x; if (nanos <= 0) return null; notEmpty.await(nanos, TimeUnit.NANOSECONDS); nanos = deadline - Utils.nanoTime(); } } finally { lock.unlock(); } }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { if (runStateAtLeast(ctl.get(), TERMINATED)) return true; while (nanos > 0) { termination.await(nanos, TimeUnit.NANOSECONDS); if (runStateAtLeast(ctl.get(), TERMINATED)) return true; nanos = deadline - Utils.nanoTime(); } return false; } finally { mainLock.unlock(); } }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { if (runStateAtLeast(ctl.get(), TERMINATED)) return true; while (nanos > 0) { termination.await(nanos, TimeUnit.NANOSECONDS); if (runStateAtLeast(ctl.get(), TERMINATED)) return true; nanos = deadline - Utils.nanoTime(); } return false; } finally { mainLock.unlock(); } }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); long deadline = Utils.nanoTime() + nanos; final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { if (runStateAtLeast(ctl.get(), TERMINATED)) return true; while (nanos > 0) { termination.await(nanos, TimeUnit.NANOSECONDS); if (runStateAtLeast(ctl.get(), TERMINATED)) return true; nanos = deadline - Utils.nanoTime(); } return false; } finally { mainLock.unlock(); } }