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.NumberAdoublevalue that may be updated atomically. See theVarHandlespecification for descriptions of the properties of atomic accesses. The implementation is based on aVarHandleguarding the access to a primitivedoublefield. 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 doubleaddAndGet(double delta)Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...).doublecompareAndExchange(double expectedValue, double newValue)Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchange(java.lang.Object...).doublecompareAndExchangeAcquire(double expectedValue, double newValue)Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeAcquire(java.lang.Object...).doublecompareAndExchangeRelease(double expectedValue, double newValue)Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeRelease(java.lang.Object...).booleancompareAndSet(double expectedValue, double newValue)Atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...).doubledoubleValue()Returns the current value of thisAtomicDoubleas anlongwith memory effects as specified byVarHandle.getVolatile(java.lang.Object...).floatfloatValue()Returns the current value of thisAtomicDoubleas anfloatafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).doubleget()Returns the current value, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).doublegetAcquire()Returns the current value, with memory effects as specified byVarHandle.getAcquire(java.lang.Object...).doublegetAndAdd(double delta)Atomically adds the given value to the current value, with memory effects as specified byVarHandle.getAndAdd(java.lang.Object...).doublegetAndSet(double newValue)Atomically sets the value tonewValueand returns the old value, with memory effects as specified byVarHandle.getAndSet(java.lang.Object...).doublegetAndUpdate(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.doublegetOpaque()Returns the current value, with memory effects as specified byVarHandle.getOpaque(java.lang.Object...).doublegetPlain()Returns the current value, with memory semantics of reading as if the variable was declared non-volatile.intintValue()Returns the current value of thisAtomicDoubleas anintafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).voidlazySet(long newValue)Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(java.lang.Object...).longlongValue()Returns the current value of thisAtomicDoubleas anlongafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).voidset(double newValue)Sets the value tonewValue, with memory effects as specified byVarHandle.setVolatile(java.lang.Object...).voidsetOpaque(double newValue)Sets the value tonewValue, with memory effects as specified byVarHandle.setOpaque(java.lang.Object...).voidsetPlain(double newValue)Sets the value tonewValue, with memory semantics of setting as if the variable was declared non-volatileand non-final.voidsetRelease(double newValue)Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(java.lang.Object...).java.lang.StringtoString()Returns the String representation of the current value.doubleupdateAndGet(java.util.function.DoubleUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function.booleanweakCompareAndSetAcquire(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(java.lang.Object...).booleanweakCompareAndSetPlain(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetPlain(java.lang.Object...).booleanweakCompareAndSetRelease(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetRelease(java.lang.Object...).booleanweakCompareAndSetVolatile(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif 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 tonewValueand 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 thisAtomicDoubleas anintafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).- Specified by:
intValuein classjava.lang.Number- Returns:
- the current value
-
longValue
public long longValue()
Returns the current value of thisAtomicDoubleas anlongafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).- Specified by:
longValuein classjava.lang.Number- Returns:
- the current value
-
floatValue
public float floatValue()
Returns the current value of thisAtomicDoubleas anfloatafter a narrowing primitive conversion, with memory effects as specified byVarHandle.getVolatile(java.lang.Object...).- Specified by:
floatValuein classjava.lang.Number- Returns:
- the current value
-
doubleValue
public double doubleValue()
Returns the current value of thisAtomicDoubleas anlongwith memory effects as specified byVarHandle.getVolatile(java.lang.Object...). Equivalent toget().- Specified by:
doubleValuein 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-volatileand 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 tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.compareAndSet(java.lang.Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif 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 tonewValueif 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 tonewValueif 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 tonewValueif 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 tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetPlain(java.lang.Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful
-
weakCompareAndSetVolatile
public boolean weakCompareAndSetVolatile(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSet(java.lang.Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful
-
weakCompareAndSetAcquire
public boolean weakCompareAndSetAcquire(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(java.lang.Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful
-
weakCompareAndSetRelease
public boolean weakCompareAndSetRelease(double expectedValue, double newValue)Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetRelease(java.lang.Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful
-
toString
public java.lang.String toString()
Returns the String representation of the current value.- Overrides:
toStringin classjava.lang.Object- Returns:
- the String representation of the current value
-
-