Class AtomicSingle
Various atomic operations for
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class AtomicSingle : object
Remarks
Methods exposed by this class provide volatile read/write of the field even if it is not declared as volatile field.
Methods
| Improve this Doc View SourceAccumulateAndGet(ref Single, Single, Func<Single, Single, Single>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.
Declaration
public static float AccumulateAndGet(this ref float value, float x, Func<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | x | Accumulator operand. |
DotNext.Func<Single, Single, Single> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Single | The updated value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
AccumulateAndGet(ref Single, Single, ValueFunc<Single, Single, Single>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.
Declaration
public static float AccumulateAndGet(this ref float value, float x, in ValueFunc<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | x | Accumulator operand. |
ValueFunc<Single, Single, Single> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Single | The updated value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
AccumulateAndGet(Single[], Int64, Single, Func<Single, Single, Single>)
Atomically updates the array element with the results of applying the given function to the array element and given values, returning the updated value.
Declaration
public static float AccumulateAndGet(this float[] array, long index, float x, Func<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | x | Accumulator operand. |
DotNext.Func<Single, Single, Single> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Single | The updated value. |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
AccumulateAndGet(Single[], Int64, Single, ValueFunc<Single, Single, Single>)
Atomically updates the array element with the results of applying the given function to the array element and given values, returning the updated value.
Declaration
public static float AccumulateAndGet(this float[] array, long index, float x, in ValueFunc<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | x | Accumulator operand. |
ValueFunc<Single, Single, Single> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Single | The updated value. |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
Add(ref Single, Single)
Adds two 64-bit floating-point numbers and replaces referenced storage with the sum, as an atomic operation.
Declaration
public static float Add(this ref float value, float operand)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | operand | The value to be added to the currently stored integer. |
Returns
Type | Description |
---|---|
Single | Result of sum operation. |
Add(Single[], Int64, Single)
Adds two 64-bit integers and replaces array element with the sum, as an atomic operation.
Declaration
public static float Add(this float[] array, long index, float operand)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | operand | The value to be added to the currently stored integer. |
Returns
Type | Description |
---|---|
Single | Result of sum operation. |
CompareAndSet(ref Single, Single, Single)
Atomically sets referenced value to the given updated value if the current value == the expected value.
Declaration
public static bool CompareAndSet(this ref float value, float expected, float update)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | expected | The expected value. |
Single | update | The new value. |
Returns
Type | Description |
---|---|
Boolean | true if successful. false return indicates that the actual value was not equal to the expected value. |
CompareAndSet(Single[], Int64, Single, Single)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static bool CompareAndSet(this float[] array, long index, float expected, float update)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | expected | The expected value. |
Single | update | The new value. |
Returns
Type | Description |
---|---|
Boolean | true if successful. false return indicates that the actual value was not equal to the expected value. |
CompareExchange(Single[], Int64, Single, Single)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static float CompareExchange(this float[] array, long index, float update, float comparand)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | update | The new value. |
Single | comparand | The expected value. |
Returns
Type | Description |
---|---|
Single | The original value of the array element. |
DecrementAndGet(ref Single)
Atomically decrements by one the current value.
Declaration
public static float DecrementAndGet(this ref float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Returns
Type | Description |
---|---|
Single | Decremented value. |
DecrementAndGet(Single[], Int64)
Atomically decrements the array element by one.
Declaration
public static float DecrementAndGet(this float[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to write into. |
Int64 | index | The index of the array element to decrement atomically. |
Returns
Type | Description |
---|---|
Single | Decremented array element. |
GetAndAccumulate(ref Single, Single, Func<Single, Single, Single>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.
Declaration
public static float GetAndAccumulate(this ref float value, float x, Func<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | x | Accumulator operand. |
DotNext.Func<Single, Single, Single> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Single | The original value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndAccumulate(ref Single, Single, ValueFunc<Single, Single, Single>)
Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.
Declaration
public static float GetAndAccumulate(this ref float value, float x, in ValueFunc<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | x | Accumulator operand. |
ValueFunc<Single, Single, Single> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Single | The original value. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndAccumulate(Single[], Int64, Single, Func<Single, Single, Single>)
Atomically updates the array element with the results of applying the given function to the array element and given values, returning the original value.
Declaration
public static float GetAndAccumulate(this float[] array, long index, float x, Func<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | x | Accumulator operand. |
DotNext.Func<Single, Single, Single> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Single | The original value of the array element. |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
GetAndAccumulate(Single[], Int64, Single, ValueFunc<Single, Single, Single>)
Atomically updates the array element with the results of applying the given function to the array element and given values, returning the original value.
Declaration
public static float GetAndAccumulate(this float[] array, long index, float x, in ValueFunc<float, float, float> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Single | x | Accumulator operand. |
ValueFunc<Single, Single, Single> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Single | The original value of the array element. |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
GetAndSet(ref Single, Single)
Modifies referenced value atomically.
Declaration
public static float GetAndSet(this ref float value, float update)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | update | A new value to be stored into managed pointer. |
Returns
Type | Description |
---|---|
Single | Original value before modification. |
GetAndSet(Single[], Int64, Single)
Modifies the array element atomically.
Declaration
public static float GetAndSet(this float[] array, long index, float update)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
Single | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
Single | Original array element before modification. |
GetAndUpdate(ref Single, Func<Single, Single>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static float GetAndUpdate(this ref float value, Func<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
DotNext.Func<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The original value. |
GetAndUpdate(ref Single, ValueFunc<Single, Single>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static float GetAndUpdate(this ref float value, in ValueFunc<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
ValueFunc<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The original value. |
GetAndUpdate(Single[], Int64, Func<Single, Single>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static float GetAndUpdate(this float[] array, long index, Func<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The original value of the array element. |
GetAndUpdate(Single[], Int64, ValueFunc<Single, Single>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static float GetAndUpdate(this float[] array, long index, in ValueFunc<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The original value of the array element. |
IncrementAndGet(ref Single)
Atomically increments by one referenced value.
Declaration
public static float IncrementAndGet(this ref float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Returns
Type | Description |
---|---|
Single | Incremented value. |
IncrementAndGet(Single[], Int64)
Atomically increments the array element by one.
Declaration
public static float IncrementAndGet(this float[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to write into. |
Int64 | index | The index of the element to increment atomically. |
Returns
Type | Description |
---|---|
Single | Incremented array element. |
SetAndGet(ref Single, Single)
Modifies value atomically.
Declaration
public static float SetAndGet(this ref float value, float update)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
Single | update | A new value to be stored into managed pointer. |
Returns
Type | Description |
---|---|
Single | A new value passed as argument. |
SetAndGet(Single[], Int64, Single)
Modifies the array element atomically.
Declaration
public static float SetAndGet(this float[] array, long index, float update)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
Single | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
Single | The array element after modification. |
UpdateAndGet(ref Single, Func<Single, Single>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static float UpdateAndGet(this ref float value, Func<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
DotNext.Func<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The updated value. |
UpdateAndGet(ref Single, ValueFunc<Single, Single>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static float UpdateAndGet(this ref float value, in ValueFunc<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single | value | Reference to a value to be modified. |
ValueFunc<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The updated value. |
UpdateAndGet(Single[], Int64, Func<Single, Single>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static float UpdateAndGet(this float[] array, long index, Func<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The updated value. |
UpdateAndGet(Single[], Int64, ValueFunc<Single, Single>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static float UpdateAndGet(this float[] array, long index, in ValueFunc<float, float> updater)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<Single, Single> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Single | The updated value. |
VolatileRead(ref Single)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.
Declaration
public static float VolatileRead(this ref float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The field to read. |
Returns
Type | Description |
---|---|
Single | The value that was read. This value is the latest written by any processor in the computer, regardless of the number of processors or the state of processor cache. |
VolatileRead(Single[], Int64)
Performs volatile read of the array element.
Declaration
public static float VolatileRead(this float[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to read from. |
Int64 | index | The array element index. |
Returns
Type | Description |
---|---|
Single | The array element. |
VolatileWrite(ref Single, Single)
Writes the specified value to the specified field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.
Declaration
public static void VolatileWrite(this ref float value, float newValue)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The field where the value is written. |
Single | newValue | The value to write. The value is written immediately so that it is visible to all processors in the computer. |
VolatileWrite(Single[], Int64, Single)
Performs volatile write to the array element.
Declaration
public static void VolatileWrite(this float[] array, long index, float value)
Parameters
Type | Name | Description |
---|---|---|
Single[] | array | The array to write into. |
Int64 | index | The array element index. |
Single | value | The new value of the array element. |