/** * Returns the number of registered parties that have arrived at * the current phase of this phaser. If this phaser has terminated, * the returned value is meaningless and arbitrary. * * @return the number of arrived parties */ public int getArrivedParties() { return arrivedOf(reconcileState()); }
/** * Returns the number of registered parties that have not yet * arrived at the current phase of this phaser. If this phaser has * terminated, the returned value is meaningless and arbitrary. * * @return the number of unarrived parties */ public int getUnarrivedParties() { return unarrivedOf(reconcileState()); }
/** * Returns a string identifying this phaser, as well as its * state. The state, in brackets, includes the String {@code * "phase = "} followed by the phase number, {@code "parties = "} * followed by the number of registered parties, and {@code * "arrived = "} followed by the number of arrived parties. * * @return a string identifying this phaser, as well as its state */ public String toString() { return stateToString(reconcileState()); }
/** * Awaits the phase of this phaser to advance from the given phase * value, returning immediately if the current phase is not equal * to the given phase value or this phaser is terminated. * * @param phase an arrival phase number, or negative value if * terminated; this argument is normally the value returned by a * previous call to {@code arrive} or {@code arriveAndDeregister}. * @return the next arrival phase number, or the argument if it is * negative, or the (negative) {@linkplain #getPhase() current phase} * if terminated */ public int awaitAdvance(int phase) { final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0) return phase; if (p == phase) return root.internalAwaitAdvance(phase, null); return p; }
long nanos = unit.toNanos(timeout); final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0)
/** * Awaits the phase of this phaser to advance from the given phase * value, throwing {@code InterruptedException} if interrupted * while waiting, or returning immediately if the current phase is * not equal to the given phase value or this phaser is * terminated. * * @param phase an arrival phase number, or negative value if * terminated; this argument is normally the value returned by a * previous call to {@code arrive} or {@code arriveAndDeregister}. * @return the next arrival phase number, or the argument if it is * negative, or the (negative) {@linkplain #getPhase() current phase} * if terminated * @throws InterruptedException if thread interrupted while waiting */ public int awaitAdvanceInterruptibly(int phase) throws InterruptedException { final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0) return phase; if (p == phase) { QNode node = new QNode(this, phase, true, false, 0L); p = root.internalAwaitAdvance(phase, node); if (node.wasInterrupted) throw new InterruptedException(); } return p; }
int phase; for (;;) { long s = (parent == null) ? state : reconcileState(); int counts = (int)s; int parties = counts >>> PARTIES_SHIFT; break; if (counts != EMPTY) { // not 1st registration if (parent == null || reconcileState() == s) { if (unarrived == 0) // wait out advance root.internalAwaitAdvance(phase, null);
final Phaser root = this.root; for (;;) { long s = (root == this) ? state : reconcileState(); int phase = (int)(s >>> PHASE_SHIFT); if (phase < 0)
long s = (root == this) ? state : reconcileState(); int phase = (int)(s >>> PHASE_SHIFT); if (phase < 0)
/** * Returns the number of registered parties that have not yet * arrived at the current phase of this phaser. If this phaser has * terminated, the returned value is meaningless and arbitrary. * * @return the number of unarrived parties */ public int getUnarrivedParties() { return unarrivedOf(reconcileState()); }
/** * Returns the number of registered parties that have arrived at * the current phase of this phaser. If this phaser has terminated, * the returned value is meaningless and arbitrary. * * @return the number of arrived parties */ public int getArrivedParties() { return arrivedOf(reconcileState()); }
/** * Returns a string identifying this phaser, as well as its * state. The state, in brackets, includes the String {@code * "phase = "} followed by the phase number, {@code "parties = "} * followed by the number of registered parties, and {@code * "arrived = "} followed by the number of arrived parties. * * @return a string identifying this phaser, as well as its state */ public String toString() { return stateToString(reconcileState()); }
/** * Awaits the phase of this phaser to advance from the given phase * value, returning immediately if the current phase is not equal * to the given phase value or this phaser is terminated. * * @param phase an arrival phase number, or negative value if * terminated; this argument is normally the value returned by a * previous call to {@code arrive} or {@code arriveAndDeregister}. * @return the next arrival phase number, or the argument if it is * negative, or the (negative) {@linkplain #getPhase() current phase} * if terminated */ public int awaitAdvance(int phase) { final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0) return phase; if (p == phase) return root.internalAwaitAdvance(phase, null); return p; }
long nanos = unit.toNanos(timeout); final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0)
/** * Awaits the phase of this phaser to advance from the given phase * value, throwing {@code InterruptedException} if interrupted * while waiting, or returning immediately if the current phase is * not equal to the given phase value or this phaser is * terminated. * * @param phase an arrival phase number, or negative value if * terminated; this argument is normally the value returned by a * previous call to {@code arrive} or {@code arriveAndDeregister}. * @return the next arrival phase number, or the argument if it is * negative, or the (negative) {@linkplain #getPhase() current phase} * if terminated * @throws InterruptedException if thread interrupted while waiting */ public int awaitAdvanceInterruptibly(int phase) throws InterruptedException { final Phaser root = this.root; long s = (root == this) ? state : reconcileState(); int p = (int)(s >>> PHASE_SHIFT); if (phase < 0) return phase; if (p == phase) { QNode node = new QNode(this, phase, true, false, 0L); p = root.internalAwaitAdvance(phase, node); if (node.wasInterrupted) throw new InterruptedException(); } return p; }
final Phaser root = this.root; for (;;) { long s = (root == this) ? state : reconcileState(); int phase = (int)(s >>> PHASE_SHIFT); int counts = (int)s; return phase; else if (counts == EMPTY || unarrived < 0) { if (root == this || reconcileState() == s) throw new IllegalStateException(badArrive(s));
break; else if (counts != EMPTY) { // not 1st registration if (par == null || reconcileState() == s) { if (unarrived == 0) // wait out advance root.internalAwaitAdvance(phase, null);
long s = (root == this) ? state : reconcileState(); int phase = (int)(s >>> PHASE_SHIFT); int counts = (int)s; return phase; else if (counts == EMPTY || unarrived < 0) { if (reconcileState() == s) throw new IllegalStateException(badArrive(s));