@Override @Suspendable public V get() throws InterruptedException, ExecutionException { try { if (done) return getValue(); Object token = sync.register(); try { for (int i = 0; !done; i++) sync.await(i); } finally { sync.unregister(token); } return getValue(); } catch (SuspendExecution e) { throw new AssertionError(e); } }
void signalSenders() { if (overflowPolicy == OverflowPolicy.BLOCK) { record("signalSenders", ""); sendersSync.signal(); } }
protected boolean set(V value) { if (done) return false; if (casSetting(0, 1)) { this.value = value; this.done = true; sync.signalAll(); return true; } else return false; }
private M timedReceive(final long timeout, final TimeUnit unit) throws SuspendExecution, InterruptedException { final Object ticket = monitor.register(); if (unit == null) // Untimed receive monitor.await(i); else if (timeout > 0) { // Timed receive monitor.await(i, left, TimeUnit.NANOSECONDS); now = System.nanoTime(); left = deadline - now; monitor.signalAll(); return ret; } else { monitor.signal(); return null; monitor.unregister(ticket);
return true; if (overflowPolicy == OverflowPolicy.BLOCK) sendersSync.register(); try { int i = 0; } finally { if (overflowPolicy == OverflowPolicy.BLOCK) sendersSync.unregister(null);
@Override public Object register() { for(Condition cond : conditions) cond.register(); return null; }
@Override public void unregister(Object registrationToken) { for(Condition cond : conditions) cond.unregister(null); }
public void await(int iter) throws SuspendExecution, InterruptedException { sync().await(iter); }
@Override public Object register() { // for queues, a simple registration is always a receive return sync.register(); }
@Override public void unregister(Object token) { if (token == null) return; SelectActionImpl<Message> action = (SelectActionImpl<Message>) token; if (action.isData()) { if (sendersSync != null) sendersSync.unregister(null); } else sync.unregister(null); }
public void await(int iter, long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException { sync().await(iter, timeout, unit); }
@Override @Suspendable public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { if (done) return getValue(); long left = unit.toNanos(timeout); final long deadline = System.nanoTime() + left; Object token = sync.register(); try { for (int i = 0; !done; i++) { sync.await(i, left, TimeUnit.NANOSECONDS); left = deadline - System.nanoTime(); if (left <= 0) throw new TimeoutException(); } } finally { sync.unregister(token); } return getValue(); } catch (SuspendExecution e) { throw new AssertionError(e); } }
@Override public void unregister(Object token) { if (token == null) return; Condition sync = dv.getSync(); if (sync != null) sync.unregister(null); } }
private boolean onQueueFull(int iter, boolean timed, long nanos) throws SuspendExecution, InterruptedException, TimeoutException { switch (overflowPolicy) { case DROP: return false; case THROW: throw new QueueCapacityExceededException(); case BLOCK: if (timed) sendersSync.await(iter, nanos, TimeUnit.NANOSECONDS); else sendersSync.await(iter); return true; case BACKOFF: if (iter > MAX_SEND_RETRIES) throw new QueueCapacityExceededException(); if (iter > 5) Strand.sleep((iter - 5) * 5); else if (iter > 4) Strand.yield(); return true; default: throw new AssertionError("Unsupportd policy: " + overflowPolicy); } }
protected boolean setException(Throwable exception) { if (done) return false; if (casSetting(0, 1)) { this.exception = exception; this.done = true; sync.signalAll(); return true; } else return false; }
boolean awaitItem() throws SuspendExecution, InterruptedException, EOFException { maybeSetCurrentStrandAsOwner(); Object n; Object token = sync.register(); for (int i = 0; !queue().hasNext(); i++) { if (isSendClosed()) { setReceiveClosed(); checkClosed(); } sync.await(i); } sync.unregister(token); return true; }
public void lock() { registrationToken = sync().register(); }
public void unlock() { sync().unregister(registrationToken); }
@Override public void close() { if (!sendClosed) { sendClosed = true; signalReceivers(); if (sendersSync != null) sendersSync.signalAll(); } }