/** * Polls and runs tasks until empty. */ final void pollAndExecAll() { for (ForkJoinTask<?> t; (t = poll()) != null;) t.doExec(); }
/** * Implementation for invoke, quietlyInvoke. * * @return status upon completion */ private int doInvoke() { int s; Thread t; ForkJoinWorkerThread wt; return (s = doExec()) < 0 ? s : ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? (wt = (ForkJoinWorkerThread)t).pool.awaitJoin(wt.workQueue, this) : externalAwaitDone(); }
/** * Executes a top-level task and any local tasks remaining * after execution. */ final void runTask(ForkJoinTask<?> task) { if ((currentSteal = task) != null) { task.doExec(); ForkJoinTask<?>[] a = array; int md = mode; ++nsteals; currentSteal = null; if (md != 0) pollAndExecAll(); else if (a != null) { int s, m = a.length - 1; while ((s = top - 1) - base >= 0) { long i = ((m & s) << ASHIFT) + ABASE; ForkJoinTask<?> t = (ForkJoinTask<?>)U.getObject(a, i); if (t == null) break; if (U.compareAndSwapObject(a, i, t, null)) { top = s; t.doExec(); } } } } }
/** * Blocks a non-worker-thread until completion or interruption. */ private int externalInterruptibleAwaitDone() throws InterruptedException { int s; ForkJoinPool cp = ForkJoinPool.common; if (Thread.interrupted()) throw new InterruptedException(); if ((s = status) >= 0 && cp != null) { if (this instanceof CountedCompleter) cp.externalHelpComplete((CountedCompleter<?>)this); else if (cp.tryExternalUnpush(this)) doExec(); } while ((s = status) >= 0) { if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { synchronized (this) { if (status >= 0) wait(); else notifyAll(); } } } return s; }
/** * Implementation for join, get, quietlyJoin. Directly handles * only cases of already-completed, external wait, and * unfork+exec. Others are relayed to ForkJoinPool.awaitJoin. * * @return status upon completion */ private int doJoin() { int s; Thread t; ForkJoinWorkerThread wt; ForkJoinPool.WorkQueue w; return (s = status) < 0 ? s : ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? (w = (wt = (ForkJoinWorkerThread)t).workQueue). tryUnpush(this) && (s = doExec()) < 0 ? s : wt.pool.awaitJoin(w, this) : externalAwaitDone(); }
found = true; if ((t = q.pollAt(b)) != null) t.doExec(); break;
s = cp.externalHelpComplete((CountedCompleter<?>)this); else if (cp.tryExternalUnpush(this)) s = doExec();
cp.externalHelpComplete((CountedCompleter<?>)this); else if (cp.tryExternalUnpush(this)) doExec();
do { joiner.currentSteal = t; t.doExec(); // clear local tasks too } while (task.status >= 0 && joiner.top != jt &&