/** * Makes available the permit for this fiber, if it was not already available. * If the fiber was blocked on {@code park} then it will unblock. * Otherwise, its next call to {@code park} is guaranteed not to block. */ @Override public final void unpark() { record(1, "Fiber", "unpark", "Unpark %s", this); task.unpark(); }
protected final void record(int level, String clazz, String method, String format) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format); }
protected final void record(int level, String clazz, String method, String format, Object arg1, Object arg2, Object arg3, Object arg4) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format, arg1, arg2, arg3, arg4); }
protected final void record(int level, String clazz, String method, String format, Object arg1, Object arg2) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format, arg1, arg2); }
@Override public void run(Fiber f) { f.record(1, "Fiber", "parkAndCustomSerialize", "Serializing fiber %s", f); writer.write(f); } })) ;
protected final void record(int level, String clazz, String method, String format, Object arg1) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format, arg1); }
@Override public final void unpark(Object unblocker) { record(1, "Fiber", "unpark", "Unpark %s by %s", this, unblocker); task.unpark(unblocker); }
protected void onResume() { record(1, "Fiber", "onResume", "Resuming %s", this); //record(2, "Fiber", "onResume", "Resuming %s at: %s", this, Arrays.toString(Thread.currentThread().getStackTrace())); if (interrupted) throw new FiberInterruptedException(); }
@Override public void run(Fiber current) { try { current.record(1, "FiberAsync", "run", "Calling requestAsync on class %s", this); registrationThread = Thread.currentThread(); requestAsync(); current.record(1, "FiberAsync", "run", "requestAsync on %s done", FiberAsync.this); } catch (Throwable t) { asyncFailed(t); } finally { registrationComplete = true; } } })) {
private boolean park1(Object blocker, PostParkActions postParkActions, long timeout, TimeUnit unit) throws SuspendExecution { record(1, "Fiber", "park", "Parking %s", this); //record(2, "Fiber", "park", "Parking %s at %s", this, Arrays.toString(Thread.currentThread().getStackTrace())); this.postParkActions = postParkActions; if (timeout > 0 & unit != null) { timeoutService.schedule(new Runnable() { @Override public void run() { fjTask.unpark(); } }, timeout, unit); } return fjTask.park1(blocker); }
protected final void record(int level, String clazz, String method, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format, arg1, arg2, arg3, arg4, arg5, arg6); }
protected final void record(int level, String clazz, String method, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { if (flightRecorder != null) record(flightRecorder.get(), level, clazz, method, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); }
final boolean exec(Object blocker, long timeout, TimeUnit unit) { if (!scheduler.isCurrentThreadInScheduler()) return false; record(1, "Fiber", "exec", "Blocker %s attempting to immediately execute %s", blocker, this); if (!tryUnpark(blocker, timeout, unit)) { record(1, "Fiber", "exec", "Blocker %s attempt to immediately execute %s FAILED", blocker, this); return false; } immediateExecHelper(); return true; }
@Override public void run(Fiber f) { f.record(1, "Fiber", "parkAndSerialize", "Serializing fiber %s", f); writer.write(f, getFiberSerializer()); } }));
void preempt() throws SuspendExecution { if (isRecordingLevel(2)) record(2, "Fiber", "preempt", "Preempting %s at %s", this, Arrays.toString(getStackTrace())); task.yield(); }
private void yieldAndUnpark1(Fiber other, Object blocker, long timeout, TimeUnit unit) throws SuspendExecution { record(1, "Fiber", "yieldAndUnpark", "Yielding %s and unparking %s blocker: %s", this, other, blocker); if (!other.exec(blocker, timeout, unit)) { other.unpark(blocker); yield1(); } }
private void yield1() throws SuspendExecution { if (isRecordingLevel(2)) record(2, "Fiber", "yield", "Yielding %s at %s", this, Arrays.toString(getStackTrace())); if (prePark != null) prePark.run(this); task.yield(); }
private void parkAndUnpark1(Fiber other, Object blocker, long timeout, TimeUnit unit) throws SuspendExecution { record(1, "Fiber", "parkAndUnpark", "Parking %s and unparking %s blocker: %s", this, other, blocker); if (!other.exec(blocker, timeout, unit)) other.unpark(blocker); park1(blocker, null, -1, null); }
private void installFiberDataInThread(Thread currentThread) { record(1, "Fiber", "installFiberDataInThread", "%s <-> %s", this, currentThread); if (!noLocals) { installFiberLocals(currentThread); installFiberContextClassLoader(currentThread); if (MAINTAIN_ACCESS_CONTROL_CONTEXT) installFiberInheritedAccessControlContext(currentThread); } setCurrentFiber(this, currentThread); }
private void restoreThreadData(Thread currentThread, Object old) { record(1, "Fiber", "restoreThreadData", "%s <-> %s", this, currentThread); if (!noLocals) { restoreThreadLocals(currentThread); restoreThreadContextClassLoader(currentThread); if (MAINTAIN_ACCESS_CONTROL_CONTEXT) restoreThreadInheritedAccessControlContext(currentThread); } setCurrentTarget(old, currentThread); }