Class AtomicReference
Provides atomic operations for the reference type.
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class AtomicReference : object
Methods
| Improve this Doc View SourceAccumulateAndGet<T>(ref T, T, Func<T, T, T>)
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 T AccumulateAndGet<T>(ref T value, T x, Func<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
T | x | Accumulator operand. |
DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
AccumulateAndGet<T>(ref T, T, ValueFunc<T, T, T>)
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 T AccumulateAndGet<T>(ref T value, T x, in ValueFunc<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
T | x | Accumulator operand. |
ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
AccumulateAndGet<T>(T[], Int64, T, Func<T, T, T>)
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 T AccumulateAndGet<T>(this T[] array, long index, T x, Func<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | x | Accumulator operand. |
DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
AccumulateAndGet<T>(T[], Int64, T, ValueFunc<T, T, T>)
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 T AccumulateAndGet<T>(this T[] array, long index, T x, in ValueFunc<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | x | Accumulator operand. |
ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
CompareAndSet<T>(ref T, T, T)
Compares two values for equality and, if they are equal, replaces the stored value.
Declaration
public static bool CompareAndSet<T>(ref T value, T expected, T update)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
T | expected | The expected value. |
T | 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. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
CompareAndSet<T>(T[], Int64, T, T)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static bool CompareAndSet<T>(this T[] array, long index, T expected, T update)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | expected | The expected value. |
T | 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. |
Type Parameters
Name | Description |
---|---|
T |
CompareExchange<T>(T[], Int64, T, T)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static T CompareExchange<T>(this T[] array, long index, T update, T comparand)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | update | The new value. |
T | comparand | The expected value. |
Returns
Type | Description |
---|---|
T | The original value of the array element. |
Type Parameters
Name | Description |
---|---|
T |
GetAndAccumulate<T>(ref T, T, Func<T, T, T>)
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 T GetAndAccumulate<T>(ref T value, T x, Func<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
T | x | Accumulator operand. |
DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
T | The original value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndAccumulate<T>(ref T, T, ValueFunc<T, T, T>)
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 T GetAndAccumulate<T>(ref T value, T x, in ValueFunc<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
T | x | Accumulator operand. |
ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
T | The original value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
Remarks
The function is applied with the current value as its first argument, and the given update as the second argument.
GetAndAccumulate<T>(T[], Int64, T, Func<T, T, T>)
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 T GetAndAccumulate<T>(this T[] array, long index, T x, Func<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | x | Accumulator operand. |
DotNext.Func<T, T, T> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
T | The original value of the array element. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
GetAndAccumulate<T>(T[], Int64, T, ValueFunc<T, T, T>)
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 T GetAndAccumulate<T>(this T[] array, long index, T x, in ValueFunc<T, T, T> accumulator)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
T | x | Accumulator operand. |
ValueFunc<T, T, T> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
T | The original value of the array element. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The function is applied with the array element as its first argument, and the given update as the second argument.
GetAndSet<T>(T[], Int64, T)
Modifies the array element atomically.
Declaration
public static T GetAndSet<T>(this T[] array, long index, T update)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
T | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
T | Original array element before modification. |
Type Parameters
Name | Description |
---|---|
T |
GetAndUpdate<T>(ref T, Func<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static T GetAndUpdate<T>(ref T value, Func<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The original value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
GetAndUpdate<T>(ref T, ValueFunc<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static T GetAndUpdate<T>(ref T value, in ValueFunc<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
ValueFunc<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The original value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
GetAndUpdate<T>(T[], Int64, Func<T, T>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static T GetAndUpdate<T>(this T[] array, long index, Func<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The original value of the array element. |
Type Parameters
Name | Description |
---|---|
T |
GetAndUpdate<T>(T[], Int64, ValueFunc<T, T>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static T GetAndUpdate<T>(this T[] array, long index, in ValueFunc<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The original value of the array element. |
Type Parameters
Name | Description |
---|---|
T |
SetAndGet<T>(T[], Int64, T)
Modifies the array element atomically.
Declaration
public static T SetAndGet<T>(this T[] array, long index, T update)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
T | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
T | The array element after modification. |
Type Parameters
Name | Description |
---|---|
T |
UpdateAndGet<T>(ref T, Func<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static T UpdateAndGet<T>(ref T value, Func<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
UpdateAndGet<T>(ref T, ValueFunc<T, T>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static T UpdateAndGet<T>(ref T value, in ValueFunc<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to update. |
ValueFunc<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T | Type of value in the memory storage. |
UpdateAndGet<T>(T[], Int64, Func<T, T>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static T UpdateAndGet<T>(this T[] array, long index, Func<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T |
UpdateAndGet<T>(T[], Int64, ValueFunc<T, T>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static T UpdateAndGet<T>(this T[] array, long index, in ValueFunc<T, T> updater)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<T, T> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
T | The updated value. |
Type Parameters
Name | Description |
---|---|
T |
VolatileRead<T>(T[], Int64)
Performs volatile read of the array element.
Declaration
public static T VolatileRead<T>(this T[] array, long index)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to read from. |
Int64 | index | The array element index. |
Returns
Type | Description |
---|---|
T | The array element. |
Type Parameters
Name | Description |
---|---|
T |
VolatileWrite<T>(T[], Int64, T)
Performs volatile write to the array element.
Declaration
public static void VolatileWrite<T>(this T[] array, long index, T element)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to write into. |
Int64 | index | The array element index. |
T | element | The new value of the array element. |
Type Parameters
Name | Description |
---|---|
T |