Lines Matching refs:guard

209    * {@code Monitor}. The monitor may check the guard at arbitrary times from any thread occupying
210 * the monitor, so code should not be written to rely on how often a guard might or might not be
233 * Evaluates this guard's boolean condition. This method is always called with the associated
355 * Enters this monitor when the guard is satisfied. Blocks indefinitely, but may be interrupted.
357 public void enterWhen(Guard guard) throws InterruptedException {
358 if (guard.monitor != this) {
366 waitInterruptibly(guard, reentrant);
376 * Enters this monitor when the guard is satisfied. Blocks indefinitely.
378 public void enterWhenUninterruptibly(Guard guard) {
379 if (guard.monitor != this) {
387 waitUninterruptibly(guard, reentrant);
397 * Enters this monitor when the guard is satisfied. Blocks at most the given time, including both
398 * the time to acquire the lock and the time to wait for the guard to be satisfied, and may be
403 public boolean enterWhen(Guard guard, long time, TimeUnit unit) throws InterruptedException {
404 if (guard.monitor != this) {
421 satisfied = waitInterruptibly(guard, remainingNanos, reentrant);
431 * Enters this monitor when the guard is satisfied. Blocks at most the given time, including
432 * both the time to acquire the lock and the time to wait for the guard to be satisfied.
436 public boolean enterWhenUninterruptibly(Guard guard, long time, TimeUnit unit) {
437 if (guard.monitor != this) {
467 satisfied = waitUninterruptibly(guard, remainingNanos, reentrant);
482 * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but
483 * does not wait for the guard to be satisfied.
487 public boolean enterIf(Guard guard) {
488 if (guard.monitor != this) {
495 satisfied = guard.isSatisfied();
505 * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does
506 * not wait for the guard to be satisfied, and may be interrupted.
510 public boolean enterIfInterruptibly(Guard guard) throws InterruptedException {
511 if (guard.monitor != this) {
518 satisfied = guard.isSatisfied();
528 * Enters this monitor if the guard is satisfied. Blocks at most the given time acquiring the
529 * lock, but does not wait for the guard to be satisfied.
533 public boolean enterIf(Guard guard, long time, TimeUnit unit) {
534 if (guard.monitor != this) {
543 satisfied = guard.isSatisfied();
553 * Enters this monitor if the guard is satisfied. Blocks at most the given time acquiring the
554 * lock, but does not wait for the guard to be satisfied, and may be interrupted.
558 public boolean enterIfInterruptibly(Guard guard, long time, TimeUnit unit)
560 if (guard.monitor != this) {
569 satisfied = guard.isSatisfied();
579 * Enters this monitor if it is possible to do so immediately and the guard is satisfied. Does not
580 * block acquiring the lock and does not wait for the guard to be satisfied.
586 public boolean tryEnterIf(Guard guard) {
587 if (guard.monitor != this) {
596 satisfied = guard.isSatisfied();
606 * Waits for the guard to be satisfied. Waits indefinitely, but may be interrupted. May be
609 public void waitFor(Guard guard) throws InterruptedException {
610 if (guard.monitor != this) {
616 waitInterruptibly(guard, true);
620 * Waits for the guard to be satisfied. Waits indefinitely. May be called only by a thread
623 public void waitForUninterruptibly(Guard guard) {
624 if (guard.monitor != this) {
630 waitUninterruptibly(guard, true);
634 * Waits for the guard to be satisfied. Waits at most the given time, and may be interrupted.
637 * @return whether the guard is now satisfied
639 public boolean waitFor(Guard guard, long time, TimeUnit unit) throws InterruptedException {
640 if (guard.monitor != this) {
646 return waitInterruptibly(guard, unit.toNanos(time), true);
650 * Waits for the guard to be satisfied. Waits at most the given time. May be called only by a
653 * @return whether the guard is now satisfied
655 public boolean waitForUninterruptibly(Guard guard, long time, TimeUnit unit) {
656 if (guard.monitor != this) {
662 return waitUninterruptibly(guard, unit.toNanos(time), true);
742 * Queries whether any threads are waiting for the given guard to become satisfied. Note that
744 * that the guard becoming satisfied in the future will awaken any threads. This method is
747 public boolean hasWaiters(Guard guard) {
748 if (guard.monitor != this) {
753 return guard.waiterCount > 0;
760 * Returns an estimate of the number of threads waiting for the given guard to become satisfied.
765 public int getWaitQueueLength(Guard guard) {
766 if (guard.monitor != this) {
771 return guard.waiterCount;
783 Guard guard = guards.get(i);
784 if ((guard == interruptedGuard) && (guard.waiterCount == 1)) {
786 // paying attention to the guard being satisfied, so find another waiter on another guard.
789 if (guard.isSatisfied()) {
790 guard.condition.signal();
796 Guard guard = guards.get(i);
797 guard.condition.signalAll();
804 private void incrementWaiters(Guard guard) {
805 int waiters = guard.waiterCount++;
807 activeGuards.add(guard);
812 private void decrementWaiters(Guard guard) {
813 int waiters = --guard.waiterCount;
815 activeGuards.remove(guard);
820 private void waitInterruptibly(Guard guard, boolean signalBeforeWaiting)
822 if (!guard.isSatisfied()) {
826 incrementWaiters(guard);
828 final Condition condition = guard.condition;
834 signalConditionsOfSatisfiedGuards(guard);
841 } while (!guard.isSatisfied());
843 decrementWaiters(guard);
849 private void waitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
850 if (!guard.isSatisfied()) {
854 incrementWaiters(guard);
856 final Condition condition = guard.condition;
859 } while (!guard.isSatisfied());
861 decrementWaiters(guard);
867 private boolean waitInterruptibly(Guard guard, long remainingNanos, boolean signalBeforeWaiting)
869 if (!guard.isSatisfied()) {
873 incrementWaiters(guard);
875 final Condition condition = guard.condition;
884 signalConditionsOfSatisfiedGuards(guard);
891 } while (!guard.isSatisfied());
893 decrementWaiters(guard);
900 private boolean waitUninterruptibly(Guard guard, long timeoutNanos,
902 if (!guard.isSatisfied()) {
909 incrementWaiters(guard);
911 final Condition condition = guard.condition;
921 signalConditionsOfSatisfiedGuards(guard);
929 } while (!guard.isSatisfied());
931 decrementWaiters(guard);