Package EDU.oswego.cs.dl.util.concurrent
Class WaitableBoolean
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
EDU.oswego.cs.dl.util.concurrent.WaitableBoolean
- All Implemented Interfaces:
Executor
,Cloneable
,Comparable
A class useful for offloading synch for boolean instance variables.
-
Field Summary
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
value_
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
Constructor Summary
ConstructorsConstructorDescriptionWaitableBoolean
(boolean initialValue) Make a new WaitableBoolean with the given initial valueWaitableBoolean
(boolean initialValue, Object lock) Make a new WaitableBoolean with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionboolean
and
(boolean b) Set value to value & b.boolean
commit
(boolean assumedValue, boolean newValue) Set value to newValue only if it is currently assumedValue.boolean
Set the value to its complementboolean
or
(boolean b) Set value to value | b.boolean
set
(boolean newValue) Set to newValue.void
Wait until value equals c, then run action if nonnull.void
Wait until value is false, then run action if nonnull.void
whenNotEqual
(boolean c, Runnable action) wait until value not equal to c, then run action if nonnull.void
wait until value is true, then run action if nonnull.boolean
xor
(boolean b) Set value to value ^ b.Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
compareTo, compareTo, compareTo, equals, get, hashCode, swap, toString
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
Constructor Details
-
WaitableBoolean
public WaitableBoolean(boolean initialValue) Make a new WaitableBoolean with the given initial value -
WaitableBoolean
Make a new WaitableBoolean with the given initial value, and using the supplied lock.
-
-
Method Details
-
set
public boolean set(boolean newValue) Description copied from class:SynchronizedBoolean
Set to newValue.- Overrides:
set
in classSynchronizedBoolean
- Returns:
- the old value
-
commit
public boolean commit(boolean assumedValue, boolean newValue) Description copied from class:SynchronizedBoolean
Set value to newValue only if it is currently assumedValue.- Overrides:
commit
in classSynchronizedBoolean
- Returns:
- true if successful
-
complement
public boolean complement()Description copied from class:SynchronizedBoolean
Set the value to its complement- Overrides:
complement
in classSynchronizedBoolean
- Returns:
- the new value
-
and
public boolean and(boolean b) Description copied from class:SynchronizedBoolean
Set value to value & b.- Overrides:
and
in classSynchronizedBoolean
- Returns:
- the new value
-
or
public boolean or(boolean b) Description copied from class:SynchronizedBoolean
Set value to value | b.- Overrides:
or
in classSynchronizedBoolean
- Returns:
- the new value
-
xor
public boolean xor(boolean b) Description copied from class:SynchronizedBoolean
Set value to value ^ b.- Overrides:
xor
in classSynchronizedBoolean
- Returns:
- the new value
-
whenFalse
Wait until value is false, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenTrue
wait until value is true, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenEqual
Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenNotEqual
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-