77 |
|
* <p> <b>Termination.</b> A phaser may enter a <em>termination</em> |
78 |
|
* state, that may be checked using method {@link #isTerminated}. Upon |
79 |
|
* termination, all synchronization methods immediately return without |
80 |
< |
* waiting for advance, as indicated by a negative return |
81 |
< |
* value. Similarly, attempts to register upon termination have no |
82 |
< |
* effect. Termination is triggered when an invocation of {@code |
83 |
< |
* onAdvance} returns {@code true}. The default implementation returns |
84 |
< |
* {@code true} if a deregistration has caused the number of |
85 |
< |
* registered parties to become zero. As illustrated below, when |
86 |
< |
* phasers control actions with a fixed number of iterations, it is |
87 |
< |
* often convenient to override this method to cause termination when |
88 |
< |
* the current phase number reaches a threshold. Method {@link |
89 |
< |
* #forceTermination} is also available to abruptly release waiting |
90 |
< |
* threads and allow them to terminate. |
80 |
> |
* waiting for advance, as indicated by a negative return value. |
81 |
> |
* Similarly, attempts to register upon termination have no effect. |
82 |
> |
* Termination is triggered when an invocation of {@code onAdvance} |
83 |
> |
* returns {@code true}. The default implementation returns {@code |
84 |
> |
* true} if a deregistration has caused the number of registered |
85 |
> |
* parties to become zero. As illustrated below, when phasers control |
86 |
> |
* actions with a fixed number of iterations, it is often convenient |
87 |
> |
* to override this method to cause termination when the current phase |
88 |
> |
* number reaches a threshold. Method {@link #forceTermination} is |
89 |
> |
* also available to abruptly release waiting threads and allow them |
90 |
> |
* to terminate. |
91 |
|
* |
92 |
|
* <p> <b>Tiering.</b> Phasers may be <em>tiered</em> (i.e., |
93 |
|
* constructed in tree structures) to reduce contention. Phasers with |
541 |
|
* |
542 |
|
* @return the arrival phase number to which this registration |
543 |
|
* applied. If this value is negative, then this phaser has |
544 |
< |
* terminated, in which casem registration has no effect. |
544 |
> |
* terminated, in which case registration has no effect. |
545 |
|
* @throws IllegalStateException if attempting to register more |
546 |
|
* than the maximum supported number of parties |
547 |
|
*/ |
563 |
|
* advance to the next phase |
564 |
|
* @return the arrival phase number to which this registration |
565 |
|
* applied. If this value is negative, then this phaser has |
566 |
< |
* terminated, in which casem registration has no effect. |
566 |
> |
* terminated, in which case registration has no effect. |
567 |
|
* @throws IllegalStateException if attempting to register more |
568 |
|
* than the maximum supported number of parties |
569 |
|
* @throws IllegalArgumentException if {@code parties < 0} |
682 |
|
*/ |
683 |
|
public int awaitAdvance(int phase) { |
684 |
|
final Phaser root = this.root; |
685 |
< |
int p = (int)((root == this? state : reconcileState()) >>> PHASE_SHIFT); |
685 |
> |
long s = (root == this) ? state : reconcileState(); |
686 |
> |
int p = (int)(s >>> PHASE_SHIFT); |
687 |
|
if (phase < 0) |
688 |
|
return phase; |
689 |
|
if (p == phase) |
709 |
|
public int awaitAdvanceInterruptibly(int phase) |
710 |
|
throws InterruptedException { |
711 |
|
final Phaser root = this.root; |
712 |
< |
int p = (int)((root == this? state : reconcileState()) >>> PHASE_SHIFT); |
712 |
> |
long s = (root == this) ? state : reconcileState(); |
713 |
> |
int p = (int)(s >>> PHASE_SHIFT); |
714 |
|
if (phase < 0) |
715 |
|
return phase; |
716 |
|
if (p == phase) { |
747 |
|
throws InterruptedException, TimeoutException { |
748 |
|
long nanos = unit.toNanos(timeout); |
749 |
|
final Phaser root = this.root; |
750 |
< |
int p = (int)((root == this? state : reconcileState()) >>> PHASE_SHIFT); |
750 |
> |
long s = (root == this) ? state : reconcileState(); |
751 |
> |
int p = (int)(s >>> PHASE_SHIFT); |
752 |
|
if (phase < 0) |
753 |
|
return phase; |
754 |
|
if (p == phase) { |