protected void signal() { if (sync != null && sync.isOwnerAlive()) sync.signal(); }
Channel(Object owner, SingleConsumerQueue<Message, ?> queue) { this.queue = (SingleConsumerQueue<Message, Object>) queue; this.owner = owner; this.sync = OwnedSynchronizer.create(owner); }
protected void signalAndTryToExecNow() { if (sync != null && sync.isOwnerAlive()) sync.signalAndTryToExecNow(); }
@Override public void signalAll() { signal(); }
@Override public void signal() { final Strand s = waiter; record("signal", "%s signalling %s", this, s); if (s != null) Strand.unpark(s, owner); }
public boolean isOwnerAlive() { return sync.isOwnerAlive(); }
public void lock() { sync().lock(); }
public void await(long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException { sync().await(timeout, unit); } }
protected QueueChannel(BasicQueue<Message> queue, OverflowPolicy overflowPolicy, boolean singleProducer, boolean singleConsumer) { this.queue = queue; if (!singleConsumer || queue instanceof CircularBuffer) this.sync = new SimpleConditionSynchronizer(this); else this.sync = new OwnedSynchronizer(this); this.overflowPolicy = overflowPolicy; this.sendersSync = overflowPolicy == OverflowPolicy.BLOCK ? new SimpleConditionSynchronizer(this) : null; this.singleProducer = singleProducer; this.singleConsumer = singleConsumer; }
protected void signalAndWait() throws SuspendExecution, InterruptedException { record("signalAndWait", ""); if (sync instanceof OwnedSynchronizer) ((OwnedSynchronizer) sync).signalAndWait(); else sync.signalAll(); }
Object receiveNode(long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException { if (timeout <= 0 || unit == null) return receiveNode(); maybeSetCurrentStrandAsOwner(); Object n; final long start = System.nanoTime(); long left = unit.toNanos(timeout); sync.lock(); try { while ((n = queue.pk()) == null) { sync.await(left, TimeUnit.NANOSECONDS); left = start + unit.toNanos(timeout) - System.nanoTime(); if (left <= 0) return null; } } finally { sync.unlock(); } return n; }
public void signalAndWait() throws SuspendExecution { final Strand s = waiter; if (s != null) { record("signal", "%s signalling %s", this, s); Strand.yieldAndUnpark(s, owner); } }
@Override public void setStrand(Strand strand) { if (owner != null && strand != owner) throw new IllegalStateException("Channel " + this + " is already owned by " + owner); this.owner = strand; this.sync = OwnedSynchronizer.create(owner); }
@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; }
public static OwnedSynchronizer create(Object owner) { if (owner instanceof Fiber) return create((Fiber) owner); else if (owner instanceof Thread) return create((Thread) owner); else if (owner instanceof Strand) return create(((Strand) owner).getUnderlying()); else throw new IllegalArgumentException("owner must be a Thread, a Fiber or a Strand, but is " + owner.getClass().getName()); }
public static OwnedSynchronizer create(Strand owner) { return create(owner.getUnderlying()); }