Package EDU.oswego.cs.dl.util.concurrent
Class WaitableLong
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
EDU.oswego.cs.dl.util.concurrent.WaitableLong
- All Implemented Interfaces:
Executor
,Cloneable
,Comparable
A class useful for offloading waiting and signalling operations
on single long variables.
-
Field Summary
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
value_
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
lock_
-
Constructor Summary
ConstructorsConstructorDescriptionWaitableLong
(long initialValue) Make a new WaitableLong with the given initial value, and using its own internal lock.WaitableLong
(long initialValue, Object lock) Make a new WaitableLong with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionlong
add
(long amount) Add amount to value (i.e., set value += amount)long
and
(long b) Set value to value & b.boolean
commit
(long assumedValue, long newValue) Set value to newValue only if it is currently assumedValue.long
Set the value to its complementlong
Decrement the value.long
divide
(long factor) Divide value by factor (i.e., set value /= factor)long
Increment the value.long
multiply
(long factor) Multiply value by factor (i.e., set value *= factor)long
or
(long b) Set value to value | b.long
set
(long newValue) Set to newValue.long
subtract
(long amount) Subtract amount from value (i.e., set value -= amount)void
Wait until value equals c, then run action if nonnull.void
whenGreater
(long c, Runnable action) wait until value greater than c, then run action if nonnull.void
whenGreaterEqual
(long c, Runnable action) wait until value greater than or equal to c, then run action if nonnull.void
wait until value less than c, then run action if nonnull.void
whenLessEqual
(long c, Runnable action) wait until value less than or equal to c, then run action if nonnull.void
whenNotEqual
(long c, Runnable action) wait until value not equal to c, then run action if nonnull.long
xor
(long b) Set value to value ^ b.Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedLong
compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
execute, getLock
-
Constructor Details
-
WaitableLong
public WaitableLong(long initialValue) Make a new WaitableLong with the given initial value, and using its own internal lock. -
WaitableLong
Make a new WaitableLong with the given initial value, and using the supplied lock.
-
-
Method Details
-
set
public long set(long newValue) Description copied from class:SynchronizedLong
Set to newValue.- Overrides:
set
in classSynchronizedLong
- Returns:
- the old value
-
commit
public boolean commit(long assumedValue, long newValue) Description copied from class:SynchronizedLong
Set value to newValue only if it is currently assumedValue.- Overrides:
commit
in classSynchronizedLong
- Returns:
- true if successful
-
increment
public long increment()Description copied from class:SynchronizedLong
Increment the value.- Overrides:
increment
in classSynchronizedLong
- Returns:
- the new value
-
decrement
public long decrement()Description copied from class:SynchronizedLong
Decrement the value.- Overrides:
decrement
in classSynchronizedLong
- Returns:
- the new value
-
add
public long add(long amount) Description copied from class:SynchronizedLong
Add amount to value (i.e., set value += amount)- Overrides:
add
in classSynchronizedLong
- Returns:
- the new value
-
subtract
public long subtract(long amount) Description copied from class:SynchronizedLong
Subtract amount from value (i.e., set value -= amount)- Overrides:
subtract
in classSynchronizedLong
- Returns:
- the new value
-
multiply
public long multiply(long factor) Description copied from class:SynchronizedLong
Multiply value by factor (i.e., set value *= factor)- Overrides:
multiply
in classSynchronizedLong
- Returns:
- the new value
-
divide
public long divide(long factor) Description copied from class:SynchronizedLong
Divide value by factor (i.e., set value /= factor)- Overrides:
divide
in classSynchronizedLong
- Returns:
- the new value
-
complement
public long complement()Set the value to its complement- Overrides:
complement
in classSynchronizedLong
- Returns:
- the new value
-
and
public long and(long b) Set value to value & b.- Overrides:
and
in classSynchronizedLong
- Returns:
- the new value
-
or
public long or(long b) Set value to value | b.- Overrides:
or
in classSynchronizedLong
- Returns:
- the new value
-
xor
public long xor(long b) Set value to value ^ b.- Overrides:
xor
in classSynchronizedLong
- Returns:
- the new value
-
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
-
whenLessEqual
wait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenLess
wait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreaterEqual
wait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreater
wait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-