Home | History | Annotate | Download | only in concurrent

Lines Matching refs:phase

64  * generation of a phaser has an associated phase number. The phase
67 * Integer.MAX_VALUE}. The use of phase numbers enables independent
76 * do not block, but return an associated <em>arrival phase
77 * number</em>; that is, the phase number of the phaser to which
78 * the arrival applied. When the final party for a given phase
79 * arrives, an optional action is performed and the phase
81 * triggering a phase advance, and are arranged by overriding
88 * argument indicating an arrival phase number, and returns when
89 * the phaser advances to (or is already at) a different phase.
115 * to override this method to cause termination when the current phase
142 * #getArrivedParties} have arrived at the current phase ({@link
144 * parties arrive, the phase advances. The values returned by these
181 * protected boolean onAdvance(int phase, int registeredParties) {
182 * return phase >= iterations || registeredParties == 0;
208 * <p>Related constructions may be used to await particular phase numbers
209 * in contexts where you are sure that the phase will never wrap around
213 * void awaitPhase(Phaser phaser, int phase) {
215 * while (p < phase) {
248 * be appropriate for extremely small per-phase task bodies (thus
272 * phase -- the generation of the barrier (bits 32-62)
290 * The phase of a subphaser is allowed to lag that of its
351 private AtomicReference<QNode> queueFor(int phase) {
352 return ((phase & 1) == 0) ? evenQ : oddQ;
384 int phase = (int)(s >>> PHASE_SHIFT);
385 if (phase < 0)
386 return phase;
396 if (onAdvance(phase, nextUnarrived))
402 int nextPhase = (phase + 1) & MAX_PHASE;
405 releaseWaiters(phase);
408 phase = parent.doArrive(ONE_DEREGISTER);
412 phase = parent.doArrive(ONE_ARRIVAL);
414 return phase;
429 int phase;
437 phase = (int)(s >>> PHASE_SHIFT);
438 if (phase < 0)
443 root.internalAwaitAdvance(phase, null);
449 long next = ((long)phase << PHASE_SHIFT) | adjust;
456 phase = parent.doRegister(1);
457 if (phase < 0)
464 ((long)phase << PHASE_SHIFT) | adjust)) {
466 phase = (int)(root.state >>> PHASE_SHIFT);
474 return phase;
478 * Resolves lagged phase propagation from root if necessary.
490 int phase, p;
491 // CAS to root phase with current parties, tripping unarrived
492 while ((phase = (int)(root.state >>> PHASE_SHIFT)) !=
496 s = (((long)phase << PHASE_SHIFT) |
497 ((phase < 0) ? (s & COUNTS_MASK) :
507 * parent, and initial phase number 0. Any thread using this
516 * unarrived parties, no parent, and initial phase number 0.
519 * next phase
544 * next phase
551 int phase = 0;
559 phase = parent.doRegister(1);
567 ((long)phase << PHASE_SHIFT) |
581 * @return the arrival phase number to which this registration
602 * advance to the next phase
603 * @return the arrival phase number to which this registration
626 * @return the arrival phase number, or a negative value if terminated
646 * @return the arrival phase number, or a negative value if terminated
667 * @return the arrival phase number, or the (negative)
668 * {@linkplain #getPhase() current phase} if terminated
677 int phase = (int)(s >>> PHASE_SHIFT);
678 if (phase < 0)
679 return phase;
686 return root.internalAwaitAdvance(phase, null);
691 if (onAdvance(phase, nextUnarrived))
697 int nextPhase = (phase + 1) & MAX_PHASE;
701 releaseWaiters(phase);
708 * Awaits the phase of this phaser to advance from the given phase
709 * value, returning immediately if the current phase is not equal
710 * to the given phase value or this phaser is terminated.
712 * @param phase an arrival phase number, or negative value if
715 * @return the next arrival phase number, or the argument if it is
716 * negative, or the (negative) {@linkplain #getPhase() current phase}
719 public int awaitAdvance(int phase) {
723 if (phase < 0)
724 return phase;
725 if (p == phase)
726 return root.internalAwaitAdvance(phase, null);
731 * Awaits the phase of this phaser to advance from the given phase
733 * while waiting, or returning immediately if the current phase is
734 * not equal to the given phase value or this phaser is
737 * @param phase an arrival phase number, or negative value if
740 * @return the next arrival phase number, or the argument if it is
741 * negative, or the (negative) {@linkplain #getPhase() current phase}
745 public int awaitAdvanceInterruptibly(int phase)
750 if (phase < 0)
751 return phase;
752 if (p == phase) {
753 QNode node = new QNode(this, phase, true, false, 0L);
754 p = root.internalAwaitAdvance(phase, node);
762 * Awaits the phase of this phaser to advance from the given phase
765 * returning immediately if the current phase is not equal to the
766 * given phase value or this phaser is terminated.
768 * @param phase an arrival phase number, or negative value if
775 * @return the next arrival phase number, or the argument if it is
776 * negative, or the (negative) {@linkplain #getPhase() current phase}
781 phase,
788 if (phase < 0)
789 return phase;
790 if (p == phase) {
791 QNode node = new QNode(this, phase, true, true, nanos);
792 p = root.internalAwaitAdvance(phase, node);
795 else if (p == phase)
825 * Returns the current phase number. The maximum phase number is
827 * zero. Upon termination, the phase number is negative,
828 * in which case the prevailing phase prior to termination
831 * @return the phase number, or a negative value if terminated
848 * the current phase of this phaser. If this phaser has terminated,
859 * arrived at the current phase of this phaser. If this phaser has
897 * Overridable method to perform an action upon impending phase
928 * protected boolean onAdvance(int phase, int parties) { return false; }
931 * @param phase the current phase number on entry to this method,
936 protected boolean onAdvance(int phase, int registeredParties) {
943 * "phase = "} followed by the phase number, {@code "parties = "}
958 "[phase = " + phaseOf(s) +
966 * Removes and signals threads from queue for phase.
968 private void releaseWaiters(int phase) {
971 AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
973 q.phase != (int)(root.state >>> PHASE_SHIFT)) {
989 * @return current phase on exit
991 private int abortWait(int phase) {
992 AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
997 if (q == null || ((t = q.thread) != null && q.phase == p))
1023 * Possibly blocks and waits for phase to advance unless aborted.
1026 * @param phase current phase
1029 * @return current phase
1031 private int internalAwaitAdvance(int phase, QNode node) {
1033 releaseWaiters(phase-1); // ensure old queue clean
1039 while ((p = (int)((s = state) >>> PHASE_SHIFT)) == phase) {
1047 node = new QNode(this, phase, false, false, 0L);
1054 AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
1056 if ((q == null || q.phase == phase) &&
1057 (int)(state >>> PHASE_SHIFT) == phase) // avoid stale enq
1074 if (p == phase && (p = (int)(state >>> PHASE_SHIFT)) == phase)
1075 return abortWait(phase); // possibly clean up on abort
1077 releaseWaiters(phase);
1086 final int phase;
1095 QNode(Phaser phaser, int phase, boolean interruptible,
1098 this.phase = phase;
1109 if (phaser.getPhase() != phase) {