/** * Returns the current strand. * This method will return a strand representing the fiber calling this method, or the current thread if this method is not * called within a fiber. * * @return A strand representing the current fiber or thread */ public static Strand currentStrand() { return Strand.currentStrand(); }
QNode(Phaser phaser, int phase, boolean interruptible, boolean timed, long nanos) { this.phaser = phaser; this.phase = phase; this.interruptible = interruptible; this.nanos = nanos; this.timed = timed; this.lastTime = timed ? System.nanoTime() : 0L; strand = Strand.currentStrand(); }
protected void maybeSetCurrentStrandAsOwner() { if (owner == null) setStrand(Strand.currentStrand()); else assert Strand.equals(owner, Strand.currentStrand()) : "This method has been called by a different strand (" + Strand.currentStrand() + ") from that owning this object (" + owner + ")"; }
/** * Convenience method to interrupt current strand. */ static void selfInterrupt() { Strand.currentStrand().interrupt(); }
protected final boolean isHeldExclusively() { // While we must in general read state before owner, // we don't need to do so to check if current strand is owner return getExclusiveOwnerStrand() == Strand.currentStrand(); }
@Override public void unregister(Object registrationToken) { final Strand currentStrand = Strand.currentStrand(); record("unregister", "%s unregister %s", this, currentStrand); if (!waiters.remove(currentStrand)) throw new IllegalMonitorStateException(); }
protected void maybeSetCurrentStrandAsOwner() { if (owner == null) setStrand(Strand.currentStrand()); else { assert Strand.equals(owner, Strand.currentStrand()) : "This method has been called by a different strand (thread or fiber) from that owning this object"; } }
@Override public Object register() { Strand.unpark(Strand.currentStrand()); return null; }
/** * Convenience method to interrupt current strand. */ static void selfInterrupt() { Strand.currentStrand().interrupt(); }
@Override public Object register() { final Strand currentStrand = Strand.currentStrand(); record("register", "%s register %s", this, currentStrand); waiters.add(currentStrand); return null; }
public void await() throws SuspendExecution { waiter = Strand.currentStrand(); while (running.get() > 0) { Strand.park(); } } }
@Override public void unregister(Object registrationToken) { final Strand currentStrand = Strand.currentStrand(); record("unregister", "%s unregister %s", this, currentStrand); if (!Strand.equals(waiter, currentStrand)) throw new IllegalMonitorStateException("attempt by " + Strand.currentStrand() + " but owned by " + waiter); waiter = null; }
protected final boolean isHeldExclusively() { // While we must in general read state before owner, // we don't need to do so to check if current strand is owner return getExclusiveOwnerStrand() == Strand.currentStrand(); }
@Override public void handleInterruptedException(InterruptedException e) { Strand.currentStrand().interrupt(); }
@Override public Object register() { final Strand currentStrand = Strand.currentStrand(); record("register", "%s register %s", this, currentStrand); if (!casWaiter(null, currentStrand)) throw new IllegalMonitorStateException("attempt by " + currentStrand + " but owned by " + waiter); return null; }
Selector(boolean priority, List<? extends SelectAction<Message>> actions) { this.id = selectorId.incrementAndGet(); this.waiter = Strand.currentStrand(); this.actions = (List<? extends SelectActionImpl<Message>>) actions; this.priority = priority; for (int i = 0; i < actions.size(); i++) { SelectActionImpl<? extends Message> sa = (SelectActionImpl<? extends Message>) actions.get(i); sa.setSelector(this); sa.setIndex(i); record("<init>", "%s added %s", this, sa); } }
protected void maybeSetCurrentStrandAsOwner() { if (owner == null) setStrand(Strand.currentStrand()); else sync.verifyOwner(); }
protected void sendSync(Message message) throws SuspendExecution { try { send0(message, true, false, 0); } catch (InterruptedException e) { Strand.currentStrand().interrupt(); } }
protected final boolean tryRelease(int releases) { int c = getState() - releases; if (Strand.currentStrand() != getExclusiveOwnerStrand()) throw new IllegalMonitorStateException(); boolean free = false; if (c == 0) { free = true; setExclusiveOwnerStrand(null); } setState(c); return free; }
/** * Performs lock. Try immediate barge, backing up to normal * acquire on failure. */ final void lock() throws SuspendExecution { if (compareAndSetState(0, 1)) setExclusiveOwnerStrand(Strand.currentStrand()); else acquire(1); }