Class Latch.Condition
java.lang.Object
org.cojen.tupl.util.Latch.Condition
- Enclosing class:
Latch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Blocks the current thread indefinitely until a signal is received.final int
Blocks the current thread until a signal is received.final int
Blocks the current thread until a signal is received.final int
Blocks the current thread until a signal is received.final int
awaitTagged
(Latch latch, long nanosTimeout) Blocks the current thread until a signal is received.final int
awaitTagged
(Latch latch, long nanosTimeout, long nanosEnd) Blocks the current thread until a signal is received.final void
clear()
Clears out all waiters and interrupts those that are threads.final boolean
isEmpty()
Returns true if no waiters are enqueued.final int
priorityAwait
(Latch latch, long nanosTimeout, long nanosEnd) Blocks the current thread until a signal is received.final void
Signals the first waiter, of any type.final void
Signals all waiters, of any type.final void
signalTagged
(Latch latch) Signals the first waiter, but only if it's a tagged waiter.final void
uponSignal
(Runnable cont) Invokes the given continuation upon the condition being signaled.final void
uponSignalTagged
(Runnable cont) Invokes the given continuation upon the condition being signaled.
-
Constructor Details
-
Condition
public Condition()
-
-
Method Details
-
isEmpty
public final boolean isEmpty()Returns true if no waiters are enqueued. Caller must hold shared or exclusive latch. -
await
Blocks the current thread indefinitely until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this condition- Returns:
- -1 if interrupted, or 1 if signaled
-
await
Blocks the current thread until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditiontimeout
- relative time to wait; infinite if <0unit
- timeout unit- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
-
await
Blocks the current thread until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditionnanosTimeout
- relative nanosecond time to wait; infinite if <0- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
-
await
Blocks the current thread until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditionnanosTimeout
- relative nanosecond time to wait; infinite if <0nanosEnd
- absolute nanosecond time to wait until; used only with >0 timeout- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
-
awaitTagged
Blocks the current thread until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditionnanosTimeout
- relative nanosecond time to wait; infinite if <0- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
- See Also:
-
awaitTagged
Blocks the current thread until a signal is received. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditionnanosTimeout
- relative nanosecond time to wait; infinite if <0nanosEnd
- absolute nanosecond time to wait until; used only with >0 timeout- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
- See Also:
-
priorityAwait
Blocks the current thread until a signal is received. This method behaves like regularawait
method except the thread is signaled ahead of all the other waiting threads. Exclusive latch must be acquired by the caller, which is released and then re-acquired by this method.- Parameters:
latch
- latch being used by this conditionnanosTimeout
- relative nanosecond time to wait; infinite if <0nanosEnd
- absolute nanosecond time to wait until; used only with >0 timeout- Returns:
- -1 if interrupted, 0 if timed out, 1 if signaled
-
uponSignal
Invokes the given continuation upon the condition being signaled. The exclusive latch must be acquired by the caller, which is retained. When the condition is signaled, the continuation is enqueued to be run by a thread which releases the exclusive latch. The releasing thread actually retains the latch and runs the continuation, effectively transferring latch ownership. The continuation must not explicitly release the latch, and any exception thrown by the continuation is passed to the uncaught exception handler of the running thread.- Parameters:
cont
- called with latch held
-
uponSignalTagged
Invokes the given continuation upon the condition being signaled. The exclusive latch must be acquired by the caller, which is retained. When the condition is signaled, the continuation is enqueued to be run by a thread which releases the exclusive latch. The releasing thread actually retains the latch and runs the continuation, effectively transferring latch ownership. The continuation must not explicitly release the latch, and any exception thrown by the continuation is passed to the uncaught exception handler of the running thread.- Parameters:
cont
- called with latch held- See Also:
-
signal
Signals the first waiter, of any type. Caller must hold exclusive latch. -
signalAll
Signals all waiters, of any type. Caller must hold exclusive latch. -
signalTagged
Signals the first waiter, but only if it's a tagged waiter. Caller must hold exclusive latch. -
clear
public final void clear()Clears out all waiters and interrupts those that are threads. Caller must hold exclusive latch.
-