--- jsr166/src/jsr166y/ForkJoinTask.java 2010/08/11 18:45:12 1.53 +++ jsr166/src/jsr166y/ForkJoinTask.java 2010/08/29 23:34:46 1.55 @@ -214,7 +214,9 @@ public abstract class ForkJoinTask im } /** - * Blocks a worker thread until completion. Called only by pool. + * Blocks a worker thread until completion. Called only by + * pool. Currently unused -- pool-based waits use timeout + * version below. */ final void internalAwaitDone() { int s; // the odd construction reduces lock bias effects @@ -231,6 +233,28 @@ public abstract class ForkJoinTask im } /** + * Blocks a worker thread until completed or timed out. Called + * only by pool. + * + * @return status on exit + */ + final int internalAwaitDone(long millis) { + int s; + if ((s = status) >= 0) { + try { + synchronized(this) { + if (UNSAFE.compareAndSwapInt(this, statusOffset, s,SIGNAL)) + wait(millis, 0); + } + } catch (InterruptedException ie) { + cancelIfTerminating(); + } + s = status; + } + return s; + } + + /** * Blocks a non-worker-thread until completion. */ private void externalAwaitDone() { @@ -643,6 +667,7 @@ public abstract class ForkJoinTask im */ boolean interrupted = false; boolean dec = false; // true if pool count decremented + long nanos = unit.toNanos(timeout); for (;;) { if (Thread.interrupted() && pool == null) { interrupted = true; @@ -653,7 +678,6 @@ public abstract class ForkJoinTask im break; if (UNSAFE.compareAndSwapInt(this, statusOffset, s, SIGNAL)) { long startTime = System.nanoTime(); - long nanos = unit.toNanos(timeout); long nt; // wait time while (status >= 0 && (nt = nanos - (System.nanoTime() - startTime)) > 0) {