long startTime = 0L; for (int k = 0;;) { if ((s = (joiner.isEmpty() ? // try to help tryHelpStealer(joiner, task) : joiner.tryRemoveAndExec(task))) == 0 &&
WorkQueue w; for (int j = 0; j < ws.length; ++j) { if ((w = ws[j]) != null && !w.isEmpty()) { replace = true; break; // in compensation range and tasks available
/** * Returns a (probably) non-empty steal queue, if one is found * during a random, then cyclic scan, else null. This method must * be retried by caller if, by the time it tries to use the queue, * it is empty. */ private WorkQueue findNonEmptyStealQueue(WorkQueue w) { // Similar to loop in scan(), but ignoring submissions int r = w.seed; r ^= r << 13; r ^= r >>> 17; w.seed = r ^= r << 5; int step = (r >>> 16) | 1; for (WorkQueue[] ws;;) { int rs = runState, m; if ((ws = workQueues) == null || (m = ws.length - 1) < 1) return null; for (int j = (m + 1) << 2; ; r += step) { WorkQueue q = ws[((r << 1) | 1) & m]; if (q != null && !q.isEmpty()) return q; else if (--j < 0) { if (runState == rs) return null; break; } } } }
/** * Stripped-down variant of awaitJoin used by timed joins. Tries * to help join only while there is continuous progress. (Caller * will then enter a timed wait.) * * @param joiner the joining worker * @param task the task * @return task status on exit */ final int helpJoinOnce(WorkQueue joiner, ForkJoinTask<?> task) { int s; while ((s = task.status) >= 0 && (joiner.isEmpty() ? tryHelpStealer(joiner, task) : joiner.tryRemoveAndExec(task)) != 0) ; return s; }
/** * Returns {@code true} if there are any tasks submitted to this * pool that have not yet begun executing. * * @return {@code true} if there are any queued submissions */ public boolean hasQueuedSubmissions() { WorkQueue[] ws; WorkQueue w; if ((ws = workQueues) != null) { for (int i = 0; i < ws.length; i += 2) { if ((w = ws[i]) != null && !w.isEmpty()) return true; } } return false; }