Class GammaTxnDouble
- java.lang.Object
-
- org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
-
- org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
-
- org.multiverse.stms.gamma.transactionalobjects.GammaTxnDouble
-
- All Implemented Interfaces:
Lock
,TxnDouble
,TxnObject
,MultiverseConstants
,GammaConstants
,GammaObject
public class GammaTxnDouble extends BaseGammaTxnRef implements TxnDouble
-
-
Field Summary
-
Fields inherited from class org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
long_value, ref_value, type
-
Fields inherited from class org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
___unsafe, identityHashCode, listeners, listenersOffset, MASK_OREC_EXCLUSIVELOCK, MASK_OREC_READBIASED, MASK_OREC_READLOCKS, MASK_OREC_READONLY_COUNT, MASK_OREC_SURPLUS, MASK_OREC_UPDATELOCK, orec, stm, valueOffset, version
-
Fields inherited from interface org.multiverse.stms.gamma.GammaConstants
FAILURE, MASK_CONFLICT, MASK_SUCCESS, MASK_UNREGISTERED, REGISTRATION_DONE, REGISTRATION_NONE, REGISTRATION_NOT_NEEDED, TRANLOCAL_COMMUTING, TRANLOCAL_CONSTRUCTING, TRANLOCAL_READ, TRANLOCAL_WRITE, TRANSACTIONTYPE_FAT_FIXED_LENGTH, TRANSACTIONTYPE_FAT_MONO, TRANSACTIONTYPE_FAT_VARIABLE_LENGTH, TRANSACTIONTYPE_LEAN_FIXED_LENGTH, TRANSACTIONTYPE_LEAN_MONO, TX_ABORTED, TX_ACTIVE, TX_COMMITTED, TX_PREPARED, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_INT, TYPE_LONG, TYPE_REF, VERSION_UNCOMMITTED
-
Fields inherited from interface org.multiverse.MultiverseConstants
LOCKMODE_EXCLUSIVE, LOCKMODE_NONE, LOCKMODE_READ, LOCKMODE_WRITE, SHAKE_BUGS, SPIN_YIELD, TRACING_ENABLED
-
-
Constructor Summary
Constructors Constructor Description GammaTxnDouble(double value)
GammaTxnDouble(GammaStm stm)
GammaTxnDouble(GammaStm stm, double value)
GammaTxnDouble(GammaTxn tx)
GammaTxnDouble(GammaTxn tx, double value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
alter(GammaTxn tx, DoubleFunction function, boolean returnOld)
double
alterAndGet(DoubleFunction function)
Alters the value stored in this Ref using the provided function and returns the result.double
alterAndGet(Txn tx, DoubleFunction function)
Alters the value stored in this Ref using the provided function and lifting on the provided txn.double
alterAndGet(GammaTxn tx, DoubleFunction function)
private double
atomicAlter(DoubleFunction function, boolean returnOld)
double
atomicAlterAndGet(DoubleFunction function)
Atomically applies the function to the current value in this ref and returns the new value.boolean
atomicCompareAndSet(double expectedValue, double newValue)
Executes a compare and set atomically.double
atomicGet()
Atomically gets the value.double
atomicGetAndAlter(DoubleFunction function)
Atomically applies the function to alter the value stored in this ref and returns the old value.double
atomicGetAndIncrement(double amount)
Atomically increments the value and returns the old value.double
atomicGetAndSet(double newValue)
Atomically sets the value and returns the previous value.private double
atomicIncrement(double amount, boolean returnOld)
double
atomicIncrementAndGet(double amount)
Atomically increments the value and returns the old value.double
atomicSet(double newValue)
Atomically sets the value and returns the new value.java.lang.String
atomicToString()
Returns a String representation of the object using the provided transaction without looking at aTxnThreadLocal
.double
atomicWeakGet()
Atomically gets the value without providing any ordering guarantees.void
await(double value)
Awaits for the value to become the given value.void
await(DoublePredicate predicate)
Awaits until the predicate holds.void
await(Txn tx, double value)
Awaits for the reference to become the given value.void
await(Txn tx, DoublePredicate predicate)
Awaits until the predicate holds using the provided txn.void
await(GammaTxn tx, double value)
void
await(GammaTxn tx, DoublePredicate predicate)
void
commute(DoubleFunction function)
Applies the function on the ref in a commuting manner.void
commute(Txn tx, DoubleFunction function)
Applies the function on the ref in a commuting manner.void
commute(GammaTxn tx, DoubleFunction function)
double
get()
Gets the value using the provided txn.double
get(Txn tx)
Gets the value using the provided txn.double
get(GammaTxn tx)
double
getAndAlter(DoubleFunction function)
Alters the value stored in this Ref using the provided function amd returns the old value.double
getAndAlter(Txn tx, DoubleFunction function)
Alters the value stored in this Ref using the function and returns the old value, using the provided txn.double
getAndAlter(GammaTxn tx, DoubleFunction function)
double
getAndIncrement(double amount)
Increments the value and returns the old value.double
getAndIncrement(Txn tx, double amount)
Increments the value and returns the old value using the provided txn.double
getAndIncrement(GammaTxn tx, double amount)
double
getAndLock(LockMode lockMode)
Gets the value and applies the lock.double
getAndLock(Txn tx, LockMode lockMode)
Gets the value using the provided txn and acquired the lock with the specified LockMode.double
getAndLock(GammaTxn tx, LockMode lockMode)
double
getAndSet(double value)
Sets the value the value and returns the new value.double
getAndSet(Txn tx, double value)
Sets the value using the provided txn.double
getAndSet(GammaTxn tx, double value)
double
getAndSetAndLock(double value, LockMode lockMode)
Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.double
getAndSetAndLock(Txn tx, double value, LockMode lockMode)
Sets the value and acquired the Lock with the provided LockMode.double
getAndSetAndLock(GammaTxn tx, double value, LockMode lockMode)
double
incrementAndGet(double amount)
Increments and gets the new value.double
incrementAndGet(Txn tx, double amount)
Increments and gets the new value using the provided txn.double
incrementAndGet(GammaTxn tx, double amount)
double
set(double value)
Sets the new value.double
set(Txn tx, double value)
Sets the new value using the provided txn.double
set(GammaTxn tx, double value)
double
setAndLock(double value, LockMode lockMode)
Sets the new value and applies the lock.double
setAndLock(Txn tx, double value, LockMode lockMode)
Sets the new value using the provided txn.double
setAndLock(GammaTxn tx, double value, LockMode lockMode)
java.lang.String
toDebugString()
Returns a debug representation of the TxnObject.java.lang.String
toString()
Returns a String representation of the Object using theTxn
on theTxnThreadLocal
.java.lang.String
toString(Txn tx)
Returns a String representation of the object using the providedTxn
.java.lang.String
toString(GammaTxn tx)
-
Methods inherited from class org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
acquire, acquire, acquire, arriveAndExclusiveLockOrBackoff, atomicCompareAndSetLong, atomicGetLong, atomicObjectGet, atomicSetLong, atomicSetObject, commit, ensure, ensure, ensure, flattenCommute, getLong, getObject, hasReadConflict, leanCommit, load, openForCommute, openForCommute, openForCommute, openForCommute, openForConstruction, openForConstruction, openForConstruction, openForConstruction, openForRead, openForRead, openForRead, openForRead, openForRead, openForRead, openForWrite, openForWrite, openForWrite, openForWrite, openForWrite, openForWrite, prepare, registerChangeListener, releaseAfterFailure, releaseAfterReading, releaseAfterUpdate, setLong, setObject, tryLockAndCheckConflict
-
Methods inherited from class org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
___removeListenersAfterWrite, ___toOrecString, arrive, arriveAndExclusiveLock, arriveAndLock, atomicGetLockMode, atomicGetLockModeAsInt, departAfterFailure, departAfterFailureAndUnlock, departAfterReading, departAfterReadingAndUnlock, departAfterUpdateAndUnlock, getLock, getLockMode, getLockMode, getLockMode, getReadBiasedThreshold, getReadLockCount, getReadLockCount, getReadonlyCount, getReadonlyCount, getStm, getSurplus, getSurplus, getVersion, hasAnyLock, hasExclusiveLock, hasExclusiveLock, hasWriteLock, hasWriteLock, hasWriteOrExclusiveLock, identityHashCode, isReadBiased, isReadBiased, lockAfterArrive, setExclusiveLock, setIsReadBiased, setReadLockCount, setReadonlyCount, setSurplus, setWriteLock, unlockByUnregistered, upgradeReadLock, upgradeWriteLock, waitForExclusiveLockToBecomeFree
-
-
-
-
Constructor Detail
-
GammaTxnDouble
public GammaTxnDouble(double value)
-
GammaTxnDouble
public GammaTxnDouble(GammaTxn tx)
-
GammaTxnDouble
public GammaTxnDouble(GammaTxn tx, double value)
-
GammaTxnDouble
public GammaTxnDouble(GammaStm stm)
-
GammaTxnDouble
public GammaTxnDouble(GammaStm stm, double value)
-
-
Method Detail
-
get
public final double get()
Description copied from interface:TxnDouble
Gets the value using the provided txn.- Specified by:
get
in interfaceTxnDouble
- Returns:
- the current value.
- See Also:
TxnDouble.atomicGet()
-
get
public final double get(Txn tx)
Description copied from interface:TxnDouble
Gets the value using the provided txn.
-
get
public final double get(GammaTxn tx)
-
getAndLock
public final double getAndLock(LockMode lockMode)
Description copied from interface:TxnDouble
Gets the value and applies the lock. If the current lockMode already is higher than the provided lockMode the Lock is not upgraded to a higher value.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
getAndLock
in interfaceTxnDouble
- Parameters:
lockMode
- the LockMode applied.- Returns:
- the current value.
- See Also:
TxnDouble.atomicGet()
-
getAndLock
public final double getAndLock(Txn tx, LockMode lockMode)
Description copied from interface:TxnDouble
Gets the value using the provided txn and acquired the lock with the specified LockMode.- Specified by:
getAndLock
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.lockMode
- the LockMode used- Returns:
- the value stored in the ref.
-
set
public final double set(double value)
Description copied from interface:TxnDouble
Sets the new value.This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
set
public final double set(Txn tx, double value)
Description copied from interface:TxnDouble
Sets the new value using the provided txn.
-
set
public final double set(GammaTxn tx, double value)
-
setAndLock
public final double setAndLock(double value, LockMode lockMode)
Description copied from interface:TxnDouble
Sets the new value and applies the lock.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
setAndLock
in interfaceTxnDouble
- Parameters:
value
- the new value.lockMode
- the used LockMode.- Returns:
- the new value.
-
setAndLock
public final double setAndLock(Txn tx, double value, LockMode lockMode)
Description copied from interface:TxnDouble
Sets the new value using the provided txn.- Specified by:
setAndLock
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.value
- the new valuelockMode
- the lockMode used.- Returns:
- the old value
-
getAndSet
public final double getAndSet(double value)
Description copied from interface:TxnDouble
Sets the value the value and returns the new value.This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
getAndSet
public final double getAndSet(Txn tx, double value)
Description copied from interface:TxnDouble
Sets the value using the provided txn.
-
getAndSet
public final double getAndSet(GammaTxn tx, double value)
-
getAndSetAndLock
public final double getAndSetAndLock(double value, LockMode lockMode)
Description copied from interface:TxnDouble
Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
getAndSetAndLock
in interfaceTxnDouble
- Parameters:
value
- the new value.lockMode
- the LockMode used.- Returns:
- the old value.
-
getAndSetAndLock
public final double getAndSetAndLock(Txn tx, double value, LockMode lockMode)
Description copied from interface:TxnDouble
Sets the value and acquired the Lock with the provided LockMode.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
getAndSetAndLock
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.value
- the new value.lockMode
- the LockMode used.- Returns:
- the old value.
-
getAndSetAndLock
public final double getAndSetAndLock(GammaTxn tx, double value, LockMode lockMode)
-
atomicGet
public final double atomicGet()
Description copied from interface:TxnDouble
Atomically gets the value. The value could be stale as soon as it is returned. This method doesn't care about any running txns. It could be that this call fails e.g. when a ref is locked. If you don't care about correct orderings, see theTxnDouble.atomicWeakGet()
.
-
atomicWeakGet
public final double atomicWeakGet()
Description copied from interface:TxnDouble
Atomically gets the value without providing any ordering guarantees. This method is extremely cheap and will never fail. So even if the ref is privatized, this call will still complete.It is the best method to call if you just want to get the current value stored.
- Specified by:
atomicWeakGet
in interfaceTxnDouble
- Returns:
- the value.
-
atomicSet
public final double atomicSet(double newValue)
Description copied from interface:TxnDouble
Atomically sets the value and returns the new value. This method doesn't care about any running txns.
-
atomicGetAndSet
public final double atomicGetAndSet(double newValue)
Description copied from interface:TxnDouble
Atomically sets the value and returns the previous value. This method doesn't care about any running txns.- Specified by:
atomicGetAndSet
in interfaceTxnDouble
- Parameters:
newValue
- the new value.- Returns:
- the old value.
-
commute
public final void commute(DoubleFunction function)
Description copied from interface:TxnDouble
Applies the function on the ref in a commuting manner. So if there are no dependencies, the function will commute. If somehow there already is a dependency or a dependency is formed on the result of the commuting function, the function will not commute and will be exactly the same as an alter.This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.
This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
commute
public final void commute(Txn tx, DoubleFunction function)
Description copied from interface:TxnDouble
Applies the function on the ref in a commuting manner. So if there are no dependencies, the function will commute. If somehow there already is a dependency or a dependency is formed on the result of the commuting function, the function will not commute and will be exactly the same as an alter.This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.
This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
commute
public final void commute(GammaTxn tx, DoubleFunction function)
-
atomicAlterAndGet
public final double atomicAlterAndGet(DoubleFunction function)
Description copied from interface:TxnDouble
Atomically applies the function to the current value in this ref and returns the new value. This method doesn't care about any running txns.- Specified by:
atomicAlterAndGet
in interfaceTxnDouble
- Parameters:
function
- the Function used- Returns:
- the new value.
-
atomicGetAndAlter
public final double atomicGetAndAlter(DoubleFunction function)
Description copied from interface:TxnDouble
Atomically applies the function to alter the value stored in this ref and returns the old value. This method doesn't care about any running txns.- Specified by:
atomicGetAndAlter
in interfaceTxnDouble
- Parameters:
function
- the Function used- Returns:
- the old value.
-
atomicAlter
private double atomicAlter(DoubleFunction function, boolean returnOld)
-
alterAndGet
public final double alterAndGet(DoubleFunction function)
Description copied from interface:TxnDouble
Alters the value stored in this Ref using the provided function and returns the result.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
alterAndGet
in interfaceTxnDouble
- Parameters:
function
- the function that alters the value stored in this Ref.- Returns:
- the new value.
-
alterAndGet
public final double alterAndGet(Txn tx, DoubleFunction function)
Description copied from interface:TxnDouble
Alters the value stored in this Ref using the provided function and lifting on the provided txn.- Specified by:
alterAndGet
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.function
- the function that alters the value stored in this Ref.- Returns:
- the new value.
-
alterAndGet
public final double alterAndGet(GammaTxn tx, DoubleFunction function)
-
getAndAlter
public final double getAndAlter(DoubleFunction function)
Description copied from interface:TxnDouble
Alters the value stored in this Ref using the provided function amd returns the old value.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
getAndAlter
in interfaceTxnDouble
- Parameters:
function
- the function that alters the value stored in this Ref.- Returns:
- the old value.
-
getAndAlter
public final double getAndAlter(Txn tx, DoubleFunction function)
Description copied from interface:TxnDouble
Alters the value stored in this Ref using the function and returns the old value, using the provided txn.- Specified by:
getAndAlter
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.function
- the function that alters the value stored in this Ref.- Returns:
- the old value
-
getAndAlter
public final double getAndAlter(GammaTxn tx, DoubleFunction function)
-
alter
public final double alter(GammaTxn tx, DoubleFunction function, boolean returnOld)
-
atomicCompareAndSet
public final boolean atomicCompareAndSet(double expectedValue, double newValue)
Description copied from interface:TxnDouble
Executes a compare and set atomically. This method doesn't care about any running txns.- Specified by:
atomicCompareAndSet
in interfaceTxnDouble
- Parameters:
expectedValue
- the expected value.newValue
- the new value.- Returns:
- true if the compareAndSwap was a success, false otherwise.
-
getAndIncrement
public final double getAndIncrement(double amount)
Description copied from interface:TxnDouble
Increments the value and returns the old value.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
getAndIncrement
in interfaceTxnDouble
- Parameters:
amount
- the amount to increment with.- Returns:
- the old value.
-
getAndIncrement
public final double getAndIncrement(Txn tx, double amount)
Description copied from interface:TxnDouble
Increments the value and returns the old value using the provided txn.- Specified by:
getAndIncrement
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.amount
- the amount to increment with.- Returns:
- the old value.
-
getAndIncrement
public final double getAndIncrement(GammaTxn tx, double amount)
-
atomicGetAndIncrement
public final double atomicGetAndIncrement(double amount)
Description copied from interface:TxnDouble
Atomically increments the value and returns the old value. This method doesn't care about any running txns.- Specified by:
atomicGetAndIncrement
in interfaceTxnDouble
- Parameters:
amount
- the amount to increase with.- Returns:
- the old value.
-
atomicIncrementAndGet
public final double atomicIncrementAndGet(double amount)
Description copied from interface:TxnDouble
Atomically increments the value and returns the old value. This method doesn't care about any running txns.- Specified by:
atomicIncrementAndGet
in interfaceTxnDouble
- Parameters:
amount
- the amount to increment with.- Returns:
- the new value.
-
atomicIncrement
private double atomicIncrement(double amount, boolean returnOld)
-
incrementAndGet
public final double incrementAndGet(double amount)
Description copied from interface:TxnDouble
Increments and gets the new value.This call lifts on the
Txn
stored in theTxnThreadLocal
.- Specified by:
incrementAndGet
in interfaceTxnDouble
- Parameters:
amount
- the amount to increment with.- Returns:
- the new value.
-
incrementAndGet
public final double incrementAndGet(Txn tx, double amount)
Description copied from interface:TxnDouble
Increments and gets the new value using the provided txn.- Specified by:
incrementAndGet
in interfaceTxnDouble
- Parameters:
tx
- theTxn
used for this operation.amount
- the amount to increment with.- Returns:
- the new value.
-
incrementAndGet
public final double incrementAndGet(GammaTxn tx, double amount)
-
await
public final void await(double value)
Description copied from interface:TxnDouble
Awaits for the value to become the given value. If the value already has the the specified value, the call continues, else a retry is done.This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
await
public final void await(Txn tx, double value)
Description copied from interface:TxnDouble
Awaits for the reference to become the given value. If the value already has the the specified value, the call continues, else a retry is done.
-
await
public final void await(GammaTxn tx, double value)
-
await
public final void await(DoublePredicate predicate)
Description copied from interface:TxnDouble
Awaits until the predicate holds. If the value already evaluates to true, the call continues else a retry is done. If the predicate throws an exception, the txn is aborted and the throwable is propagated.This call lifts on the
Txn
stored in theTxnThreadLocal
.
-
await
public final void await(Txn tx, DoublePredicate predicate)
Description copied from interface:TxnDouble
Awaits until the predicate holds using the provided txn. If the value already evaluates to true, the call continues else a retry is done. If the predicate throws an exception, the txn is aborted and the throwable is propagated.
-
await
public final void await(GammaTxn tx, DoublePredicate predicate)
-
toDebugString
public final java.lang.String toDebugString()
Description copied from interface:TxnObject
Returns a debug representation of the TxnObject. The data used doesn't have to be consistent, it is a best effort. This method doesn't rely on a running transaction.- Specified by:
toDebugString
in interfaceTxnObject
- Returns:
- the debug representation of the TxnObject.
-
toString
public final java.lang.String toString()
Description copied from interface:TxnObject
Returns a String representation of the Object using theTxn
on theTxnThreadLocal
.
-
toString
public final java.lang.String toString(Txn tx)
Description copied from interface:TxnObject
Returns a String representation of the object using the providedTxn
.
-
toString
public final java.lang.String toString(GammaTxn tx)
-
atomicToString
public final java.lang.String atomicToString()
Description copied from interface:TxnObject
Returns a String representation of the object using the provided transaction without looking at aTxnThreadLocal
. The outputted value doesn't need to be consistent from some point in time, only a best effort is made.- Specified by:
atomicToString
in interfaceTxnObject
- Returns:
- the String representation.
-
-