edu.rit.pj.reduction
Class SharedByte
- java.lang.Object
-
- java.lang.Number
-
- edu.rit.pj.reduction.SharedByte
-
- All Implemented Interfaces:
- java.io.Serializable
public class SharedByte extends java.lang.NumberClass SharedByte provides a reduction variable for a value of type byte.Class SharedByte is multiple thread safe. The methods use lock-free atomic compare-and-set.
Note: Class SharedByte is implemented using class java.util.concurrent.atomic.AtomicInteger. The byte value is stored as an int whose values are restricted to the range of type byte.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SharedByte()Construct a new byte reduction variable with the initial value 0.SharedByte(byte initialValue)Construct a new byte reduction variable with the given initial value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description byteaddAndGet(byte value)Add the given value to this reduction variable and return the new value.booleancompareAndSet(byte expect, byte update)Atomically set this reduction variable to the given updated value if the current value equals the expected value.bytedecrementAndGet()Subtract one from this reduction variable and return the new value.doubledoubleValue()Returns this reduction variable's current value converted to type double.floatfloatValue()Returns this reduction variable's current value converted to type float.byteget()Returns this reduction variable's current value.bytegetAndAdd(byte value)Add the given value to this reduction variable and return the previous value.bytegetAndDecrement()Subtract one from this reduction variable and return the previous value.bytegetAndIncrement()Add one to this reduction variable and return the previous value.bytegetAndSet(byte value)Set this reduction variable to the given value and return the previous value.byteincrementAndGet()Add one to this reduction variable and return the new value.intintValue()Returns this reduction variable's current value converted to type int.longlongValue()Returns this reduction variable's current value converted to type long.bytereduce(byte value, ByteOp op)Combine this reduction variable with the given value using the given operation.voidset(byte value)Set this reduction variable to the given value.java.lang.StringtoString()Returns a string version of this reduction variable.booleanweakCompareAndSet(byte expect, byte update)Atomically set this reduction variable to the given updated value if the current value equals the expected value.
-
-
-
Constructor Detail
-
SharedByte
public SharedByte()
Construct a new byte reduction variable with the initial value 0.
-
SharedByte
public SharedByte(byte initialValue)
Construct a new byte reduction variable with the given initial value.- Parameters:
initialValue- Initial value.
-
-
Method Detail
-
get
public byte get()
Returns this reduction variable's current value.- Returns:
- Current value.
-
set
public void set(byte value)
Set this reduction variable to the given value.- Parameters:
value- New value.
-
getAndSet
public byte getAndSet(byte value)
Set this reduction variable to the given value and return the previous value.- Parameters:
value- New value.- Returns:
- Previous value.
-
compareAndSet
public boolean compareAndSet(byte expect, byte update)Atomically set this reduction variable to the given updated value if the current value equals the expected value.- Parameters:
expect- Expected value.update- Updated value.- Returns:
- True if the update happened, false otherwise.
-
weakCompareAndSet
public boolean weakCompareAndSet(byte expect, byte update)Atomically set this reduction variable to the given updated value if the current value equals the expected value. May fail spuriously.- Parameters:
expect- Expected value.update- Updated value.- Returns:
- True if the update happened, false otherwise.
-
getAndIncrement
public byte getAndIncrement()
Add one to this reduction variable and return the previous value.- Returns:
- Previous value.
-
getAndDecrement
public byte getAndDecrement()
Subtract one from this reduction variable and return the previous value.- Returns:
- Previous value.
-
getAndAdd
public byte getAndAdd(byte value)
Add the given value to this reduction variable and return the previous value.- Parameters:
value- Value to add.- Returns:
- Previous value.
-
incrementAndGet
public byte incrementAndGet()
Add one to this reduction variable and return the new value.- Returns:
- New value.
-
decrementAndGet
public byte decrementAndGet()
Subtract one from this reduction variable and return the new value.- Returns:
- New value.
-
addAndGet
public byte addAndGet(byte value)
Add the given value to this reduction variable and return the new value.- Parameters:
value- Value to add.- Returns:
- New value.
-
reduce
public byte reduce(byte value, ByteOp op)Combine this reduction variable with the given value using the given operation. The result is stored back into this reduction variable and is returned.- Parameters:
value- Value.op- Binary operation.- Returns:
- (This variable) op (value).
-
toString
public java.lang.String toString()
Returns a string version of this reduction variable.- Overrides:
toStringin classjava.lang.Object- Returns:
- String version.
-
intValue
public int intValue()
Returns this reduction variable's current value converted to type int.- Specified by:
intValuein classjava.lang.Number- Returns:
- Current value.
-
longValue
public long longValue()
Returns this reduction variable's current value converted to type long.- Specified by:
longValuein classjava.lang.Number- Returns:
- Current value.
-
floatValue
public float floatValue()
Returns this reduction variable's current value converted to type float.- Specified by:
floatValuein classjava.lang.Number- Returns:
- Current value.
-
doubleValue
public double doubleValue()
Returns this reduction variable's current value converted to type double.- Specified by:
doubleValuein classjava.lang.Number- Returns:
- Current value.
-
-
DMelt 3.0 © DataMelt by jWork.ORG