--- jsr166/src/jsr166y/ForkJoinTask.java 2010/11/23 10:51:18 1.71 +++ jsr166/src/jsr166y/ForkJoinTask.java 2010/11/28 21:21:03 1.73 @@ -238,13 +238,16 @@ public abstract class ForkJoinTask im * only by pool. */ final void internalAwaitDone(long millis, int nanos) { - if (status >= 0) { + int s = status; + if ((s == 0 && + UNSAFE.compareAndSwapInt(this, statusOffset, 0, SIGNAL)) || + s > 0) { try { // the odd construction reduces lock bias effects synchronized (this) { - if (status > 0 || - UNSAFE.compareAndSwapInt(this, statusOffset, - 0, SIGNAL)) + if (status > 0) wait(millis, nanos); + else + notifyAll(); } } catch (InterruptedException ie) { cancelIfTerminating(); @@ -258,17 +261,22 @@ public abstract class ForkJoinTask im private void externalAwaitDone() { if (status >= 0) { boolean interrupted = false; - synchronized(this) { - int s; - while ((s = status) >= 0) { - if (s == 0 && - !UNSAFE.compareAndSwapInt(this, statusOffset, - 0, SIGNAL)) - continue; - try { - wait(); - } catch (InterruptedException ie) { - interrupted = true; + synchronized (this) { + for (;;) { + int s = status; + if (s == 0) + UNSAFE.compareAndSwapInt(this, statusOffset, + 0, SIGNAL); + else if (s < 0) { + notifyAll(); + break; + } + else { + try { + wait(); + } catch (InterruptedException ie) { + interrupted = true; + } } } } @@ -286,14 +294,17 @@ public abstract class ForkJoinTask im throw new InterruptedException(); if (status >= 0) { long startTime = timed ? System.nanoTime() : 0L; - synchronized(this) { - int s; - while ((s = status) >= 0) { + synchronized (this) { + for (;;) { long nt; - if (s == 0 && - !UNSAFE.compareAndSwapInt(this, statusOffset, - 0, SIGNAL)) - continue; + int s = status; + if (s == 0) + UNSAFE.compareAndSwapInt(this, statusOffset, + 0, SIGNAL); + else if (s < 0) { + notifyAll(); + break; + } else if (!timed) wait(); else if ((nt = nanos - (System.nanoTime()-startTime)) > 0L)