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