@Nullable private T pollObject(long timeoutMs) throws InterruptedException { long nanos = TIME_UNIT.toNanos(timeoutMs); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { while (objects.isEmpty()) { if (nanos <= 0) { return null; } nanos = notEnough.awaitNanos(nanos); } return objects.pop(); } finally { lock.unlock(); } }
@Override public void resume() throws InterruptedException { pauseLock.lockInterruptibly(); try { pauseRequested = false; shouldResume.signalAll(); long nanos = TimeUnit.SECONDS.toNanos(5); while (isPaused()) { if (nanos <= 0L) { throw new RuntimeException("Resume command was not accepted within 5 seconds"); } nanos = shouldResume.awaitNanos(nanos); } } finally { pauseLock.unlock(); } }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { for (;;) { if (runStateAtLeast(ctl.get(), TERMINATED)) return true; if (nanos <= 0) return false; nanos = termination.awaitNanos(nanos); } } finally { mainLock.unlock(); } }
try { while (pauseNanos > 0 && !aborted && condition.getAsBoolean()) { pauseNanos = pausing.awaitNanos(pauseNanos); pauseLock.unlock(); timeUpdate.addAndGet(System.nanoTime() - start);
lock.lockInterruptibly(); try { for (;;) { leader = thisThread; try { available.awaitNanos(delay); } finally { if (leader == thisThread) if (leader == null && q.peek() != null) available.signal(); lock.unlock();
public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { E x; while ((x = unlinkFirst()) == null) { if (nanos <= 0) return null; nanos = notEmpty.awaitNanos(nanos); } return x; } finally { lock.unlock(); } }
@Override public boolean waitForAvailable(long timeoutMillis) { boolean available = isAvailable(); if (available) { return true; } long remains = TimeUnit.MILLISECONDS.toNanos(timeoutMillis); final ReentrantLock _look = lock; _look.lock(); try { // avoid "spurious wakeup" occurs while (!(available = isAvailable())) { signalNeeded = 1; // set signal needed to true if ((remains = notifyCondition.awaitNanos(remains)) <= 0) { break; } } } catch (InterruptedException e) { ThrowUtil.throwException(e); } finally { _look.unlock(); } return available; }
@VisibleForTesting public void resume() throws InterruptedException { pauseLock.lockInterruptibly(); try { pauseRequested = false; shouldResume.signalAll(); long nanos = TimeUnit.SECONDS.toNanos(5); while (isPaused()) { if (nanos <= 0L) { throw new RuntimeException("Resume command was not accepted within 5 seconds"); } nanos = shouldResume.awaitNanos(nanos); } } finally { pauseLock.unlock(); } }
reopenCond.awaitNanos(sleepNS); } else { break; return; } finally { reopenLock.unlock();
public RunnableScheduledFuture<?> take() throws InterruptedException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { for (;;) { leader = thisThread; try { available.awaitNanos(delay); } finally { if (leader == thisThread) if (leader == null && queue[0] != null) available.signal(); lock.unlock();
public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { E x; while ((x = unlinkLast()) == null) { if (nanos <= 0) return null; nanos = notEmpty.awaitNanos(nanos); } return x; } finally { lock.unlock(); } }
@Override public boolean waitForAvailable(long timeoutMillis) { boolean available = isAvailable(); if (available) { return true; } long remains = TimeUnit.MILLISECONDS.toNanos(timeoutMillis); final ReentrantLock _look = lock; _look.lock(); try { // avoid "spurious wakeup" occurs while (!(available = isAvailable())) { signalNeeded = 1; // set signal needed to true if ((remains = notifyCondition.awaitNanos(remains)) <= 0) { break; } } } catch (InterruptedException e) { ThrowUtil.throwException(e); } finally { _look.unlock(); } return available; }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { long nanoTimeWait = unit.toNanos(timeout); _unfinishedLock.lock(); try { while (!_unfinishedFutures.isEmpty()) { if ((nanoTimeWait = _unfinishedCondition.awaitNanos( nanoTimeWait)) <= 0) { return false; } } } finally { _unfinishedLock.unlock(); } return true; }
trip.await(); else if (nanos > 0L) nanos = trip.awaitNanos(nanos); } catch (InterruptedException ie) { if (g == generation && ! g.broken) { lock.unlock();
private List<T> pollObjects(int elementNum, long timeoutMs) throws InterruptedException { long nanos = TIME_UNIT.toNanos(timeoutMs); final List<T> list = new ArrayList<>(elementNum); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); try { while (objects.size() < elementNum) { if (nanos <= 0) { return Collections.emptyList(); } nanos = notEnough.awaitNanos(nanos); } for (int i = 0; i < elementNum; i++) { list.add(objects.pop()); } return list; } finally { lock.unlock(); } }
@Override public boolean waitForAvailable(long timeoutMillis) { if (connector.isDirectoryAvailable(directory)) { return true; } long remains = TimeUnit.MILLISECONDS.toNanos(timeoutMillis); boolean available = false; final ReentrantLock _look = lock; _look.lock(); try { signalNeeded.set(true); // avoid "spurious wakeup" occurs while (!(available = connector.isDirectoryAvailable(directory))) { if ((remains = notifyCondition.awaitNanos(remains)) <= 0) { break; } } } catch (InterruptedException e) { ThrowUtil.throwException(e); } finally { _look.unlock(); } return available || connector.isDirectoryAvailable(directory); } };
/** * Wait for the condition to become something else as {@link State#RequestSent} or {@link State#Initial}. * {@link #reportSuccess()}, {@link #reportFailure()} and {@link #reportFailure(Exception)} will either set this * synchronization point to {@link State#Success} or {@link State#Failure}. If none of them is set after the * connections reply timeout, this method will set the state of {@link State#NoResponse}. * @throws InterruptedException */ private void waitForConditionOrTimeout() throws InterruptedException { long remainingWait = TimeUnit.MILLISECONDS.toNanos(connection.getReplyTimeout()); while (state == State.RequestSent || state == State.Initial) { if (remainingWait <= 0) { state = State.NoResponse; break; } remainingWait = condition.awaitNanos(remainingWait); } }
managementMayBeNecessary.awaitNanos(MANAGEMENT_WAIT_TIMEOUT_NANOS); giant.unlock();
public E poll(long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; lock.lockInterruptibly(); E result; try { while ( (result = dequeue()) == null && nanos > 0) nanos = notEmpty.awaitNanos(nanos); } finally { lock.unlock(); } return result; }
@Override public boolean waitForAvailable(long timeoutMillis) { if (connector.isDirectoryAvailable(directory)) { return true; } long remains = TimeUnit.MILLISECONDS.toNanos(timeoutMillis); boolean available = false; final ReentrantLock _look = lock; _look.lock(); try { signalNeeded.set(true); // avoid "spurious wakeup" occurs while (!(available = connector.isDirectoryAvailable(directory))) { if ((remains = notifyCondition.awaitNanos(remains)) <= 0) { break; } } } catch (InterruptedException e) { ThrowUtil.throwException(e); } finally { _look.unlock(); } return available || connector.isDirectoryAvailable(directory); } };