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

Comparing jsr166/src/main/java/util/concurrent/Phaser.java (file contents):
Revision 1.27 by jsr166, Thu Nov 18 07:51:21 2010 UTC vs.
Revision 1.28 by jsr166, Fri Nov 19 02:16:48 2010 UTC

# Line 304 | Line 304 | public class Phaser {
304       */
305      private int doArrive(long adj) {
306          for (;;) {
307 <            long s;
308 <            int phase, unarrived;
309 <            if ((phase = (int)((s = state) >>> PHASE_SHIFT)) < 0)
307 >            long s = state;
308 >            int phase = (int)(s >>> PHASE_SHIFT);
309 >            if (phase < 0)
310                  return phase;
311 <            else if ((unarrived = (int)s & UNARRIVED_MASK) == 0)
311 >            int unarrived = (int)s & UNARRIVED_MASK;
312 >            if (unarrived == 0)
313                  checkBadArrive(s);
314              else if (UNSAFE.compareAndSwapLong(this, stateOffset, s, s-=adj)) {
315                  if (unarrived == 1) {
315                    Phaser par;
316                      long p = s & LPARTIES_MASK; // unshifted parties field
317                      long lu = p >>> PARTIES_SHIFT;
318                      int u = (int)lu;
319                      int nextPhase = (phase + 1) & MAX_PHASE;
320                      long next = ((long)nextPhase << PHASE_SHIFT) | p | lu;
321 <                    if ((par = parent) == null) {
321 >                    final Phaser parent = this.parent;
322 >                    if (parent == null) {
323                          if (onAdvance(phase, u))
324                              next |= TERMINATION_PHASE; // obliterate phase
325                          UNSAFE.compareAndSwapLong(this, stateOffset, s, next);
326                          releaseWaiters(phase);
327                      }
328                      else {
329 <                        par.doArrive(u == 0?
330 <                                     ONE_ARRIVAL|ONE_PARTY : ONE_ARRIVAL);
331 <                        if ((int)(par.state >>> PHASE_SHIFT) != nextPhase ||
329 >                        parent.doArrive((u == 0) ?
330 >                                        ONE_ARRIVAL|ONE_PARTY : ONE_ARRIVAL);
331 >                        if ((int)(parent.state >>> PHASE_SHIFT) != nextPhase ||
332                              ((int)(state >>> PHASE_SHIFT) != nextPhase &&
333                               !UNSAFE.compareAndSwapLong(this, stateOffset,
334                                                          s, next)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines