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)
| 628 | |
| 629 | |
| 630 | public boolean enterIf(Guard guard) { |
| 631 | if (guard.monitor != this) { |
| 632 | throw new IllegalMonitorStateException(); |
| 633 | } |
| 634 | final ReentrantLock lock = this.lock; |
| 635 | lock.lock(); |
| 636 | boolean satisfied = false; |
| 637 | try { |
| 638 | return satisfied = guard.isSatisfied(); |
| 639 | } finally { |
| 640 | if (!satisfied) { |
| 641 | lock.unlock(); |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does |
no test coverage detected