@VisibleForTesting void resetState() { task.tryUnpark(null); assert task.getState() == FiberTask.RUNNABLE; }
private boolean tryUnpark(Object unblocker, long timeout, TimeUnit unit) { long start = 0; for (int i = 0;; i++) { Object b = getBlocker(); boolean tu; if ((unblocker != null ? b == unblocker : true) && (tu = task.tryUnpark(unblocker))) return true; if ((start = isTimeoutExpired(i, start, timeout, unit)) < 0) return false; } }
/** * Executes fiber on this thread, after waiting until the given blocker is indeed the fiber's blocker, and that the fiber is not being run concurrently. * * @param blocker * @return {@code true} if the task has been executed by this method; {@code false} otherwise. */ final boolean exec(Object blocker, ParkAction prePark) { if (!scheduler.isCurrentThreadInScheduler()) return false; record(1, "Fiber", "exec", "Blocker %s attempting to immediately execute %s", blocker, this); if (blocker != getBlocker() || !task.tryUnpark(blocker)) { record(1, "Fiber", "exec", "Blocker %s attempt to immediately execute %s FAILED", blocker, this); return false; } this.prePark = prePark; immediateExecHelper(); return true; }