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