ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/Phaser.java
(Generate patch)

Comparing jsr166/src/jsr166y/Phaser.java (file contents):
Revision 1.76 by jsr166, Sat Oct 15 21:46:25 2011 UTC vs.
Revision 1.78 by jsr166, Sun Nov 18 18:03:10 2012 UTC

# Line 17 | Line 17 | import java.util.concurrent.locks.LockSu
17   * {@link java.util.concurrent.CountDownLatch CountDownLatch}
18   * but supporting more flexible usage.
19   *
20 < * <p> <b>Registration.</b> Unlike the case for other barriers, the
20 > * <p><b>Registration.</b> Unlike the case for other barriers, the
21   * number of parties <em>registered</em> to synchronize on a phaser
22   * may vary over time.  Tasks may be registered at any time (using
23   * methods {@link #register}, {@link #bulkRegister}, or forms of
# Line 30 | Line 30 | import java.util.concurrent.locks.LockSu
30   * (However, you can introduce such bookkeeping by subclassing this
31   * class.)
32   *
33 < * <p> <b>Synchronization.</b> Like a {@code CyclicBarrier}, a {@code
33 > * <p><b>Synchronization.</b> Like a {@code CyclicBarrier}, a {@code
34   * Phaser} may be repeatedly awaited.  Method {@link
35   * #arriveAndAwaitAdvance} has effect analogous to {@link
36   * java.util.concurrent.CyclicBarrier#await CyclicBarrier.await}. Each
# Line 74 | Line 74 | import java.util.concurrent.locks.LockSu
74   *
75   * </ul>
76   *
77 < * <p> <b>Termination.</b> A phaser may enter a <em>termination</em>
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 value.
# Line 89 | Line 89 | import java.util.concurrent.locks.LockSu
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.,
92 > * <p><b>Tiering.</b> Phasers may be <em>tiered</em> (i.e.,
93   * constructed in tree structures) to reduce contention. Phasers with
94   * large numbers of parties that would otherwise experience heavy
95   * synchronization contention costs may instead be set up so that
# Line 271 | Line 271 | public class Phaser {
271      private static final int  PHASE_SHIFT     = 32;
272      private static final int  UNARRIVED_MASK  = 0xffff;      // to mask ints
273      private static final long PARTIES_MASK    = 0xffff0000L; // to mask longs
274 +    private static final long COUNTS_MASK     = 0xffffffffL;
275      private static final long TERMINATION_BIT = 1L << 63;
276  
277      // some special values
# Line 453 | Line 454 | public class Phaser {
454       * subphasers have not yet done so, in which case they must finish
455       * their own advance by setting unarrived to parties (or if
456       * parties is zero, resetting to unregistered EMPTY state).
456     * However, this method may also be called when "floating"
457     * subphasers with possibly some unarrived parties are merely
458     * catching up to current phase, in which case counts are
459     * unaffected.
457       *
458       * @return reconciled state
459       */
# Line 464 | Line 461 | public class Phaser {
461          final Phaser root = this.root;
462          long s = state;
463          if (root != this) {
464 <            int phase, u, p;
465 <            // CAS root phase with current parties; possibly trip unarrived
464 >            int phase, p;
465 >            // CAS to root phase with current parties, tripping unarrived
466              while ((phase = (int)(root.state >>> PHASE_SHIFT)) !=
467                     (int)(s >>> PHASE_SHIFT) &&
468                     !UNSAFE.compareAndSwapLong
469                     (this, stateOffset, s,
470                      s = (((long)phase << PHASE_SHIFT) |
471 <                         (s & PARTIES_MASK) |
472 <                         ((p = (int)s >>> PARTIES_SHIFT) == 0 ? EMPTY :
473 <                          ((u = (int)s & UNARRIVED_MASK) == 0 && phase >= 0) ?
477 <                          p : u))))
471 >                         ((phase < 0) ? (s & COUNTS_MASK) :
472 >                          (((p = (int)s >>> PARTIES_SHIFT) == 0) ? EMPTY :
473 >                           ((s & PARTIES_MASK) | p))))))
474                  s = state;
475          }
476          return s;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines