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.77 by jsr166, Mon Oct 17 23:37:19 2011 UTC

# 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