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.74 by jsr166, Wed Jun 1 21:04:30 2011 UTC vs.
Revision 1.75 by dl, Wed Sep 21 12:30:39 2011 UTC

# Line 360 | Line 360 | public class Phaser {
360                      throw new IllegalStateException(badArrive(s));
361              }
362              else if (UNSAFE.compareAndSwapLong(this, stateOffset, s, s-=adj)) {
363 +                long n = s & PARTIES_MASK;  // base of next state
364 +                int nextUnarrived = (int)n >>> PARTIES_SHIFT;
365                  if (unarrived == 0) {
366 <                    long n = s & PARTIES_MASK;  // base of next state
367 <                    int nextUnarrived = (int)n >>> PARTIES_SHIFT;
368 <                    if (root != this)
369 <                        return parent.doArrive(nextUnarrived == 0);
370 <                    if (onAdvance(phase, nextUnarrived))
371 <                        n |= TERMINATION_BIT;
372 <                    else if (nextUnarrived == 0)
373 <                        n |= EMPTY;
366 >                    if (root == this) {
367 >                        if (onAdvance(phase, nextUnarrived))
368 >                            n |= TERMINATION_BIT;
369 >                        else if (nextUnarrived == 0)
370 >                            n |= EMPTY;
371 >                        else
372 >                            n |= nextUnarrived;
373 >                        n |= (long)((phase + 1) & MAX_PHASE) << PHASE_SHIFT;
374 >                        UNSAFE.compareAndSwapLong(this, stateOffset, s, n);
375 >                    }
376 >                    else if (nextUnarrived == 0) { // propagate deregistration
377 >                        phase = parent.doArrive(true);
378 >                        UNSAFE.compareAndSwapLong(this, stateOffset,
379 >                                                  s, s | EMPTY);
380 >                    }
381                      else
382 <                        n |= nextUnarrived;
374 <                    n |= (long)((phase + 1) & MAX_PHASE) << PHASE_SHIFT;
375 <                    UNSAFE.compareAndSwapLong(this, stateOffset, s, n);
382 >                        phase = parent.doArrive(false);
383                      releaseWaiters(phase);
384                  }
385                  return phase;
# Line 392 | Line 399 | public class Phaser {
399          final Phaser parent = this.parent;
400          int phase;
401          for (;;) {
402 <            long s = state;
402 >            long s = (parent == null) ? state : reconcileState();
403              int counts = (int)s;
404              int parties = counts >>> PARTIES_SHIFT;
405              int unarrived = counts & UNARRIVED_MASK;
# Line 458 | Line 465 | public class Phaser {
465                      s = (((long)phase << PHASE_SHIFT) |
466                           (s & PARTIES_MASK) |
467                           ((p = (int)s >>> PARTIES_SHIFT) == 0 ? EMPTY :
468 <                          (u = (int)s & UNARRIVED_MASK) == 0 ? p : u))))
468 >                          ((u = (int)s & UNARRIVED_MASK) == 0 && phase >= 0) ?
469 >                          p : u))))
470                  s = state;
471          }
472          return s;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines