/** * Executes a non-top-level (stolen) task. */ final void runSubtask(ForkJoinTask<?> t) { if (t != null) { ForkJoinTask<?> ps = currentSteal; currentSteal = t; t.doExec(); currentSteal = ps; } }
/** * Polls and runs tasks until empty. */ private void pollAndExecAll() { for (ForkJoinTask<?> t; (t = poll()) != null;) t.doExec(); }
/** * Pops and runs tasks until empty. */ private void popAndExecAll() { // A bit faster than repeated pop calls ForkJoinTask<?>[] a; int m, s; long j; ForkJoinTask<?> t; while ((a = array) != null && (m = a.length - 1) >= 0 && (s = top - 1) - base >= 0 && (t = ((ForkJoinTask<?>) U.getObject(a, j = ((m & s) << ASHIFT) + ABASE))) != null) { if (U.compareAndSwapObject(a, j, t, null)) { top = s; t.doExec(); } } }
/** * Implementation for invoke, quietlyInvoke. * * @return status upon completion */ private int doInvoke() { int s; Thread t; ForkJoinWorkerThread wt; if ((s = doExec()) >= 0) { if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) s = (wt = (ForkJoinWorkerThread)t).pool.awaitJoin(wt.workQueue, this); else s = externalAwaitDone(); } return s; }
/** * Executes a top-level task and any local tasks remaining * after execution. */ final void runTask(ForkJoinTask<?> t) { if (t != null) { currentSteal = t; t.doExec(); if (top != base) { // process remaining local tasks if (mode == 0) popAndExecAll(); else pollAndExecAll(); } ++nsteals; currentSteal = null; } }
/** * 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; if ((s = status) >= 0) { if (((t = Thread.currentThread()) instanceof ForkJoinWorkerThread)) { if (!(w = (wt = (ForkJoinWorkerThread)t).workQueue). tryUnpush(this) || (s = doExec()) >= 0) s = wt.pool.awaitJoin(w, this); } else s = externalAwaitDone(); } return s; }
localTask.doExec(); WorkQueue q = findNonEmptyStealQueue(w); if (q != null) {
task.doExec(); return stat;
/** * If present, pops and executes the given task, or any other * cancelled task * * @return false if any other non-cancelled task exists in local queue */ private boolean localHelpJoinTask(ForkJoinTask<?> joinMe) { int s, i; ForkJoinTask<?>[] q; ForkJoinTask<?> t; if ((s = queueTop) != queueBase && (q = queue) != null && (i = (q.length - 1) & --s) >= 0 && (t = q[i]) != null) { if (t != joinMe && t.status >= 0) return false; if (UNSAFE.compareAndSwapObject (q, (i << ASHIFT) + ABASE, t, null)) { queueTop = s; // or putOrderedInt t.doExec(); } } return true; }
ForkJoinTask<?> ps = currentSteal; currentSteal = t; t.doExec(); currentSteal = ps;
/** * Runs the given task, plus any local tasks until queue is empty */ final void execTask(ForkJoinTask<?> t) { currentSteal = t; for (;;) { if (t != null) t.doExec(); if (queueTop == queueBase) break; t = locallyFifo ? locallyDeqTask() : popTask(); } ++stealCount; currentSteal = null; }
ForkJoinTask<?> ps = currentSteal; currentSteal = t; t.doExec(); currentSteal = ps; helped = true;
locallyFifo ? locallyDeqTask() : popTask()) != null) { currentSteal = t; t.doExec(); currentSteal = ps;