--- jsr166/src/jsr166y/ForkJoinTask.java 2012/01/26 00:08:13 1.81 +++ jsr166/src/jsr166y/ForkJoinTask.java 2012/01/31 01:51:13 1.85 @@ -93,7 +93,7 @@ import java.lang.reflect.Constructor; * performs the most common form of parallel invocation: forking a set * of tasks and joining them all. * - *

In the most typical usages, a fork-join pair act like a a call + *

In the most typical usages, a fork-join pair act like a call * (fork) and return (join) from a parallel recursive function. As is * the case with other forms of recursive calls, returns (joins) * should be performed innermost-first. For example, {@code a.fork(); @@ -143,10 +143,10 @@ import java.lang.reflect.Constructor; * use these {@code protected} methods or marks for any purpose, but * they may be of use in the construction of specialized subclasses. * For example, parallel graph traversals can use the supplied methods - * to avoid revisiting nodes/tasks that have already been - * processed. Also, completion based designs can use them to record - * that one subtask has completed. (Method names for marking are bulky - * in part to encourage definition of methods that reflect their usage + * to avoid revisiting nodes/tasks that have already been processed. + * Also, completion based designs can use them to record that one + * subtask has completed. (Method names for marking are bulky in part + * to encourage definition of methods that reflect their usage * patterns.) * *

Most base support methods are {@code final}, to prevent @@ -235,7 +235,7 @@ public abstract class ForkJoinTask im /** * Marks completion and wakes up threads waiting to join this * task, also clearing signal request bits. A specialization for - * NORMAL completion is in method doExec + * NORMAL completion is in method doExec. * * @param completion one of NORMAL, CANCELLED, EXCEPTIONAL * @return completion status on exit @@ -395,11 +395,16 @@ public abstract class ForkJoinTask im * @return status upon completion */ private int doInvoke() { - int s; - if ((s = doExec()) < 0) - return s; - else - return doJoin(); + int s; Thread t; + if ((s = doExec()) >= 0) { + if (!((t = Thread.currentThread()) instanceof ForkJoinWorkerThread)) + s = externalAwaitDone(); + else { + ForkJoinWorkerThread wt = (ForkJoinWorkerThread)t; + s = awaitJoin(wt.workQueue, wt.pool); + } + } + return s; } // Exception table support @@ -434,7 +439,7 @@ public abstract class ForkJoinTask im * any ForkJoinPool will call helpExpungeStaleExceptions when its * pool becomes isQuiescent. */ - static final class ExceptionNode extends WeakReference>{ + static final class ExceptionNode extends WeakReference> { final Throwable ex; ExceptionNode next; final long thrower; // use id not ref to avoid weak cycles @@ -1070,9 +1075,9 @@ public abstract class ForkJoinTask im * ClassCastException}. */ public static void helpQuiesce() { - ForkJoinWorkerThread w = + ForkJoinWorkerThread wt = (ForkJoinWorkerThread)Thread.currentThread(); - w.pool.helpQuiescePool(w.workQueue); + wt.pool.helpQuiescePool(wt.workQueue); } /** @@ -1225,9 +1230,9 @@ public abstract class ForkJoinTask im * have zero queued tasks, so compensate by a factor of * (#idle/#active) threads. */ - ForkJoinWorkerThread w = + ForkJoinWorkerThread wt = (ForkJoinWorkerThread)Thread.currentThread(); - return w.workQueue.queueSize() - w.pool.idlePerActive(); + return wt.workQueue.queueSize() - wt.pool.idlePerActive(); } // Extension methods @@ -1325,9 +1330,9 @@ public abstract class ForkJoinTask im * @return a task, or {@code null} if none are available */ protected static ForkJoinTask pollTask() { - ForkJoinWorkerThread w = + ForkJoinWorkerThread wt = (ForkJoinWorkerThread)Thread.currentThread(); - return w.pool.nextTaskFor(w.workQueue); + return wt.pool.nextTaskFor(wt.workQueue); } // Mark-bit operations