@Override public Object register() { // for queues, a simple registration is always a receive return sync.register(); }
@Override public Object register() { for(Condition cond : conditions) cond.register(); return null; }
public void lock() { registrationToken = sync().register(); }
@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 @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 attemptReceive(long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException, TimeoutException, EOFException { checkClosed(); final Condition sync = channel.sync; long left = unit.toNanos(timeout); final long deadline = System.nanoTime() + left; Object token = sync.register(); try { for (int i = 0; !consumer.hasNext(); i++) { if (channel.isSendClosed()) { setReceiveClosed(); checkClosed(); } sync.await(i, left, TimeUnit.NANOSECONDS); left = deadline - System.nanoTime(); if (left <= 0) throw new TimeoutException(); } consumer.poll0(); } finally { sync.unregister(token); } }
@Override public Object register(SelectAction<V> action1) { SelectActionImpl<V> action = (SelectActionImpl<V>)action1; if (action.isData()) throw new UnsupportedOperationException("Send is not supported by DelayedValChanel"); Condition sync = dv.getSync(); if (sync == null) { if (!action.lease()) return null; action.setItem(dv.getValue()); action.won(); return null; } sync.register(); return action; }
return true; if (overflowPolicy == OverflowPolicy.BLOCK) sendersSync.register(); try { int i = 0;
final Object token = sync.register(); try { for (int i = 0;; i++) {
boolean awaitItem(long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException, EOFException { if (unit == null) return awaitItem(); if (timeout <= 0) return queue().hasNext(); maybeSetCurrentStrandAsOwner(); Object n; long left = unit.toNanos(timeout); final long deadline = System.nanoTime() + left; Object token = sync.register(); try { for (int i = 0; !queue().hasNext(); i++) { if (isSendClosed()) { setReceiveClosed(); checkClosed(); } sync.await(i, left, TimeUnit.NANOSECONDS); left = deadline - System.nanoTime(); if (left <= 0) return false; } } finally { sync.unregister(token); } return true; }
final long deadline = System.nanoTime() + left; Object token = sync.register(); try { for (int i = 0; (m = queue().poll()) == null; i++) {
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; }
private M timedReceive(final long timeout, final TimeUnit unit) throws SuspendExecution, InterruptedException { final Object ticket = monitor.register();
void attemptReceive() throws EOFException, SuspendExecution, InterruptedException { checkClosed(); final Condition sync = channel.sync; Object token = sync.register(); try { for (int i = 0; !consumer.hasNext(); i++) { if (channel.isSendClosed()) { setReceiveClosed(); checkClosed(); } sync.await(i); } consumer.poll0(); } finally { sync.unregister(token); } }
@Override public Message receive() throws SuspendExecution, InterruptedException { if (receiveClosed) return closeValue(); Message m; boolean closed; final Object token = sync.register(); try { for (int i = 0;; i++) { closed = isSendClosed(); // must be read BEFORE queue.poll() if ((m = queue.poll()) != null) break; // i can be > 0 if task state is LEASED if (closed) { setReceiveClosed(); return closeValue(); } sync.await(i); } } finally { sync.unregister(token); } assert m != null; signalSenders(); return m; }
@Override public Message receive() throws SuspendExecution, InterruptedException { if (isClosed()) return null; try { maybeSetCurrentStrandAsOwner(); Message m; Object token = sync.register(); try { for (int i = 0; (m = queue().poll()) == null; i++) { if (isSendClosed()) { setReceiveClosed(); checkClosed(); } sync.await(i); } } finally { sync.unregister(token); } signalSenders(); return m; } catch (EOFException e) { return null; } }