Class Notifier
java.lang.Object
ca.spottedleaf.concurrentutil.lock.Notifier
Synchronisation utility which may be used to park threads waiting
on a single condition.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanblock()Requires any thread enteringwaitUntilReady()to park until notified.booleanUnblocks and unparks all waiting threads.booleanThis function is equivalent to invokingnotifyThreads()followed byblock()except that it is atomic and possibly faster.voidThis function causes this thread to be parked if blocked.
-
Constructor Details
-
Notifier
public Notifier(boolean blocked)
-
-
Method Details
-
notifyThreads
public boolean notifyThreads()Unblocks and unparks all waiting threads. It is guaranteed that all threads which are parked when this function is invoked are unparked.- Returns:
trueif the blocked state was changed tofalse, orfalseif not blocked
-
notifyThreadsAndBlock
public boolean notifyThreadsAndBlock()This function is equivalent to invokingnotifyThreads()followed byblock()except that it is atomic and possibly faster. This function is useful for causing all threads previously parked to become schedulable again while forcing new threads which enterwaitUntilReady()to park.- Returns:
trueif the blocked state istrue,falseotherwise
-
block
public boolean block()Requires any thread enteringwaitUntilReady()to park until notified.- Returns:
falseif the blocked state is already set,trueif this thread set the blocked state.
-
waitUntilReady
public void waitUntilReady()This function causes this thread to be parked if blocked. The thread is only unblocked when a notification arrives, such as throughnotifyThreads().
-