Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does not wait for the guard to be satisfied. @return whether the monitor was entered, which guarantees that the guard is now satisfied
(Guard guard)
| 626 | |
| 627 | |
| 628 | public boolean enterIf(Guard guard) { |
| 629 | if (guard.monitor != this) { |
| 630 | throw new IllegalMonitorStateException(); |
| 631 | } |
| 632 | final ReentrantLock lock = this.lock; |
| 633 | lock.lock(); |
| 634 | boolean satisfied = false; |
| 635 | try { |
| 636 | return satisfied = guard.isSatisfied(); |
| 637 | } finally { |
| 638 | if (!satisfied) { |
| 639 | lock.unlock(); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does |
no test coverage detected