public static void yieldAndUnpark(Strand other) throws SuspendExecution { if (other.isFiber() && isCurrentFiber()) Fiber.yieldAndUnpark((Fiber) other); else if (!other.isFiber() && !isCurrentFiber()) { // might be made faster on Linux if SwitchTo syscall is introduced into the kernel. other.unpark(); //Thread.yield(); - it's a shame to yield now as we'll shortly block } else { other.unpark(); //yield(); - it's a shame to yield now as we'll shortly block } }
@SuppressWarnings("CallToThreadDumpStack") public static void exit(int code, Throwable t, String filename) { final Strand currentStrand = Strand.currentStrand(); if (flightRecorder != null) { flightRecorder.record(1, "DEBUG EXIT REQUEST ON STRAND " + currentStrand + ": " + Arrays.toString(currentStrand.getStackTrace())); if (t != null) flightRecorder.record(1, "CAUSED BY " + t + ": " + Arrays.toString(currentStrand.getStackTrace())); flightRecorder.stop(); } if (requestShutdown.compareAndSet(false, true)) { System.err.println("DEBUG EXIT REQUEST ON STRAND " + currentStrand + (currentStrand.isFiber() ? " (THREAD " + Thread.currentThread() + ")" : "") + ": SHUTTING DOWN THE JVM."); Thread.dumpStack(); if (t != null) { System.err.println("CAUSED BY " + t); t.printStackTrace(); } dumpRecorder(filename); if (!isUnitTest()) // Calling System.exit() in gradle unit tests breaks gradle System.exit(code); } }
public static void yieldAndUnpark(Strand other, Object blocker) throws SuspendExecution { if (canTransferControl(other)) Fiber.yieldAndUnpark((Fiber) other, blocker); else if (!other.isFiber() && !isCurrentFiber()) { // might be made faster on Linux if SwitchTo syscall is introduced into the kernel. other.unpark(blocker); //Thread.yield(); - it's a shame to yield now as we'll shortly block } else { other.unpark(blocker); //yield(); - it's a shame to yield now as we'll shortly block } }
@Override public void signal() { /* * We must wake up the first waiter that is actually parked. Otherwise, by the time the awakened waiter calls * unregister(), another one may block, and we may need to wake that one. */ for (final Strand s : waiters) { if (s.isFiber()) { if (FiberControl.unpark((Fiber) s, owner)) { record("signal", "%s signalled %s", this, s); return; } } else { // TODO: We can't tell (atomically) if a thread is actually parked, so we'll wake them all up. // We may consider a more complex solution, a-la AbstractQueuedSynchronizer for threads // (i.e. with a wrapper node, containing the state) record("signal", "%s signalling %s", this, s); Strand.unpark(s, owner); } } } }
/** * Returns the actor associated with the given strand, or {@code null} if none is. */ public static Actor getActor(Strand s) { final ActorRunner runner; if (s.isFiber()) runner = (ActorRunner) ((Fiber) s.getUnderlying()).getTarget(); else runner = (ActorRunner) Strand.unwrapSuspendable(ThreadAccess.getTarget((Thread) s.getUnderlying())); if (runner == null) return null; return runner.getActor(); } //</editor-fold>
public static void parkAndUnpark(Strand other) throws SuspendExecution { if (canTransferControl(other)) Fiber.parkAndUnpark((Fiber) other); else if (!other.isFiber() && !isCurrentFiber()) { // might be made faster on Linux if SwitchTo syscall is introduced into the kernel. other.unpark(); LockSupport.park(); } else { other.unpark(); park(); } }
public static void parkAndUnpark(Strand other, Object blocker) throws SuspendExecution { if (canTransferControl(other)) Fiber.parkAndUnpark((Fiber) other, blocker); else if (!other.isFiber() && !isCurrentFiber()) { // might be made faster on Linux if SwitchTo syscall is introduced into the kernel. other.unpark(blocker); LockSupport.park(blocker); } else { other.unpark(blocker); park(blocker); } }
final V run0() throws InterruptedException, SuspendExecution { JMXActorsMonitor.getInstance().actorStarted(ref); final Strand strand = runner.getStrand(); // runner might be nulled by running actor if (!strand.isFiber()) currentActor.set(this); try { } finally { record(1, "Actor", "die", "Actor %s is now dead of %s", this, getDeathCause()); if (!strand.isFiber()) currentActor.set(null); JMXActorsMonitor.getInstance().actorTerminated(ref, strand);
private ActorInfo getActorInfo(SmallActorMonitor mon) { final ActorRef actor = mon.actor; if (actor == null) return null; return new ActorInfo(mon.id, actor.getName(), LocalActor.getStrand(actor).isFiber(), mon.messages, LocalActor.getQueueLength(actor), (int) mon.restartCounter.get(), mon.deathCauses.toArray(new String[0]), getMailbox(actor), getStackTrace(actor)); }
long lastTime = timed ? System.nanoTime() : 0L; Strand w = Strand.currentStrand(); int spins = (w.isFiber() ? 0 : -1); // no spins in fiber; otherwise, initialized after first item and cancel checks
if (collector.isFiber()) { Fiber f = (Fiber) collector.getUnderlying(); f.join();