Package org.neo4j.gds.core.concurrency
Class AtomicDouble
- java.lang.Object
-
- java.lang.Number
-
- org.neo4j.gds.core.concurrency.AtomicDouble
-
- All Implemented Interfaces:
java.io.Serializable
public final class AtomicDouble extends java.lang.Number
Adouble
value that may be updated atomically. See theVarHandle
specification for descriptions of the properties of atomic accesses. The implementation is based on aVarHandle
guarding the access to a primitivedouble
field. For double, numeric (e.g.getAndAdd
) as well as bitwise (e.g.getOpaque
) atomic update method access modes compare values using their bitwise representation (seeDouble.doubleToRawLongBits(double)
).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AtomicDouble()
Creates a new AtomicDouble with initial value0
.AtomicDouble(double initialValue)
Creates a new AtomicDouble with the given initial value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
addAndGet(double delta)
Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...)
.double
compareAndExchange(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchange(java.lang.Object...)
.double
compareAndExchangeAcquire(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchangeAcquire(java.lang.Object...)
.double
compareAndExchangeRelease(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchangeRelease(java.lang.Object...)
.boolean
compareAndSet(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...)
.double
doubleValue()
Returns the current value of thisAtomicDouble
as anlong
with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.float
floatValue()
Returns the current value of thisAtomicDouble
as anfloat
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.double
get()
Returns the current value, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.double
getAcquire()
Returns the current value, with memory effects as specified byVarHandle.getAcquire(java.lang.Object...)
.double
getAndAdd(double delta)
Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...)
.double
getAndSet(double newValue)
Atomically sets the value tonewValue
and returns the old value, with memory effects as specified byVarHandle.getAndSet(java.lang.Object...)
.double
getAndUpdate(java.util.function.DoubleUnaryOperator updateFunction)
Atomically updates (with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...)
) the current value with the results of applying the given function, returning the previous value.double
getOpaque()
Returns the current value, with memory effects as specified byVarHandle.getOpaque(java.lang.Object...)
.double
getPlain()
Returns the current value, with memory semantics of reading as if the variable was declared non-volatile
.int
intValue()
Returns the current value of thisAtomicDouble
as anint
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.void
lazySet(long newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setRelease(java.lang.Object...)
.long
longValue()
Returns the current value of thisAtomicDouble
as anlong
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.void
set(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setVolatile(java.lang.Object...)
.void
setOpaque(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setOpaque(java.lang.Object...)
.void
setPlain(double newValue)
Sets the value tonewValue
, with memory semantics of setting as if the variable was declared non-volatile
and non-final
.void
setRelease(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setRelease(java.lang.Object...)
.java.lang.String
toString()
Returns the String representation of the current value.double
updateAndGet(java.util.function.DoubleUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function.boolean
weakCompareAndSetAcquire(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(java.lang.Object...)
.boolean
weakCompareAndSetPlain(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetPlain(java.lang.Object...)
.boolean
weakCompareAndSetRelease(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetRelease(java.lang.Object...)
.boolean
weakCompareAndSetVolatile(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSet(java.lang.Object...)
.
-
-
-
Method Detail
-
get
public double get()
Returns the current value, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.- Returns:
- the current value
-
set
public void set(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setVolatile(java.lang.Object...)
.- Parameters:
newValue
- the new value
-
lazySet
public void lazySet(long newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setRelease(java.lang.Object...)
.- Parameters:
newValue
- the new value
-
getAndSet
public double getAndSet(double newValue)
Atomically sets the value tonewValue
and returns the old value, with memory effects as specified byVarHandle.getAndSet(java.lang.Object...)
.- Parameters:
newValue
- the new value- Returns:
- the previous value
-
getAndAdd
public double getAndAdd(double delta)
Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...)
.- Parameters:
delta
- the value to add- Returns:
- the previous value
-
addAndGet
public double addAndGet(double delta)
Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...)
.- Parameters:
delta
- the value to add- Returns:
- the updated value
-
getAndUpdate
public double getAndUpdate(java.util.function.DoubleUnaryOperator updateFunction)
Atomically updates (with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...)
) the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public double updateAndGet(java.util.function.DoubleUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function.- Parameters:
updateFunction
- the update function- Returns:
- the updated value
-
intValue
public int intValue()
Returns the current value of thisAtomicDouble
as anint
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.- Specified by:
intValue
in classjava.lang.Number
- Returns:
- the current value
-
longValue
public long longValue()
Returns the current value of thisAtomicDouble
as anlong
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.- Specified by:
longValue
in classjava.lang.Number
- Returns:
- the current value
-
floatValue
public float floatValue()
Returns the current value of thisAtomicDouble
as anfloat
after a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
.- Specified by:
floatValue
in classjava.lang.Number
- Returns:
- the current value
-
doubleValue
public double doubleValue()
Returns the current value of thisAtomicDouble
as anlong
with memory effects as specified byVarHandle.getVolatile(java.lang.Object...)
. Equivalent toget()
.- Specified by:
doubleValue
in classjava.lang.Number
- Returns:
- the current value
-
getPlain
public double getPlain()
Returns the current value, with memory semantics of reading as if the variable was declared non-volatile
.- Returns:
- the current value
-
setPlain
public void setPlain(double newValue)
Sets the value tonewValue
, with memory semantics of setting as if the variable was declared non-volatile
and non-final
.- Parameters:
newValue
- the new value
-
getOpaque
public double getOpaque()
Returns the current value, with memory effects as specified byVarHandle.getOpaque(java.lang.Object...)
.- Returns:
- the current value
-
setOpaque
public void setOpaque(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setOpaque(java.lang.Object...)
.- Parameters:
newValue
- the new value
-
getAcquire
public double getAcquire()
Returns the current value, with memory effects as specified byVarHandle.getAcquire(java.lang.Object...)
.- Returns:
- the current value
-
setRelease
public void setRelease(double newValue)
Sets the value tonewValue
, with memory effects as specified byVarHandle.setRelease(java.lang.Object...)
.- Parameters:
newValue
- the new value
-
compareAndSet
public boolean compareAndSet(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful. False return indicates that the actual value was not equal to the expected value.
-
compareAndExchange
public double compareAndExchange(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchange(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
compareAndExchangeAcquire
public double compareAndExchangeAcquire(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchangeAcquire(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
compareAndExchangeRelease
public double compareAndExchangeRelease(double expectedValue, double newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
, with memory effects as specified byVarHandle.compareAndExchangeRelease(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
weakCompareAndSetPlain
public boolean weakCompareAndSetPlain(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetPlain(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful
-
weakCompareAndSetVolatile
public boolean weakCompareAndSetVolatile(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSet(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful
-
weakCompareAndSetAcquire
public boolean weakCompareAndSetAcquire(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful
-
weakCompareAndSetRelease
public boolean weakCompareAndSetRelease(double expectedValue, double newValue)
Possibly atomically sets the value tonewValue
if the current value== expectedValue
, with memory effects as specified byVarHandle.weakCompareAndSetRelease(java.lang.Object...)
.- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful
-
toString
public java.lang.String toString()
Returns the String representation of the current value.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the String representation of the current value
-
-