Class AtomicInt32
Various atomic operations for
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class AtomicInt32 : 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 Int32, Int32, Func<Int32, Int32, Int32>)
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 int AccumulateAndGet(this ref int value, int x, Func<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | x | Accumulator operand. |
DotNext.Func<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Int32 | 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 Int32, Int32, ValueFunc<Int32, Int32, Int32>)
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 int AccumulateAndGet(this ref int value, int x, in ValueFunc<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | x | Accumulator operand. |
ValueFunc<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Int32 | 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(Int32[], Int64, Int32, Func<Int32, Int32, Int32>)
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 int AccumulateAndGet(this int[] array, long index, int x, Func<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | x | Accumulator operand. |
DotNext.Func<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Int32 | 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(Int32[], Int64, Int32, ValueFunc<Int32, Int32, Int32>)
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 int AccumulateAndGet(this int[] array, long index, int x, in ValueFunc<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | x | Accumulator operand. |
ValueFunc<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Int32 | 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 Int32, Int32)
Adds two 32-bit integers and replaces referenced integer with the sum, as an atomic operation.
Declaration
public static int Add(this ref int value, int operand)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | operand | The value to be added to the currently stored integer. |
Returns
Type | Description |
---|---|
Int32 | Result of sum operation. |
Add(Int32[], Int64, Int32)
Adds two 32-bit integers and replaces array element with the sum, as an atomic operation.
Declaration
public static int Add(this int[] array, long index, int operand)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | operand | The value to be added to the currently stored integer. |
Returns
Type | Description |
---|---|
Int32 | Result of sum operation. |
CompareAndSet(ref Int32, Int32, Int32)
Atomically sets the referenced value to the given updated value if the current value == the expected value.
Declaration
public static bool CompareAndSet(this ref int value, int expected, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | expected | The expected value. |
Int32 | 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(Int32[], Int64, Int32, Int32)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static bool CompareAndSet(this int[] array, long index, int expected, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | expected | The expected value. |
Int32 | 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(Int32[], Int64, Int32, Int32)
Atomically sets array element to the given updated value if the array element == the expected value.
Declaration
public static int CompareExchange(this int[] array, long index, int update, int comparand)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | update | The new value. |
Int32 | comparand | The expected value. |
Returns
Type | Description |
---|---|
Int32 | The original value of the array element. |
DecrementAndGet(ref Int32)
Atomically decrements the referenced value by one.
Declaration
public static int DecrementAndGet(this ref int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Returns
Type | Description |
---|---|
Int32 | Decremented value. |
DecrementAndGet(Int32[], Int64)
Atomically decrements the array element by one.
Declaration
public static int DecrementAndGet(this int[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to write into. |
Int64 | index | The index of the array element to decrement atomically. |
Returns
Type | Description |
---|---|
Int32 | Decremented array element. |
GetAndAccumulate(ref Int32, Int32, Func<Int32, Int32, Int32>)
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 int GetAndAccumulate(this ref int value, int x, Func<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | x | Accumulator operand. |
DotNext.Func<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Int32 | 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 Int32, Int32, ValueFunc<Int32, Int32, Int32>)
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 int GetAndAccumulate(this ref int value, int x, in ValueFunc<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | x | Accumulator operand. |
ValueFunc<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments |
Returns
Type | Description |
---|---|
Int32 | 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(Int32[], Int64, Int32, Func<Int32, Int32, Int32>)
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 int GetAndAccumulate(this int[] array, long index, int x, Func<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | x | Accumulator operand. |
DotNext.Func<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Int32 | 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(Int32[], Int64, Int32, ValueFunc<Int32, Int32, Int32>)
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 int GetAndAccumulate(this int[] array, long index, int x, in ValueFunc<int, int, int> accumulator)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
Int32 | x | Accumulator operand. |
ValueFunc<Int32, Int32, Int32> | accumulator | A side-effect-free function of two arguments. |
Returns
Type | Description |
---|---|
Int32 | 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 Int32, Int32)
Modifies the referenced value atomically.
Declaration
public static int GetAndSet(this ref int value, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | update | A new value to be stored into managed pointer. |
Returns
Type | Description |
---|---|
Int32 | Original value before modification. |
GetAndSet(Int32[], Int64, Int32)
Modifies the array element atomically.
Declaration
public static int GetAndSet(this int[] array, long index, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
Int32 | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
Int32 | Original array element before modification. |
GetAndUpdate(ref Int32, Func<Int32, Int32>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static int GetAndUpdate(this ref int value, Func<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
DotNext.Func<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The original value. |
GetAndUpdate(ref Int32, ValueFunc<Int32, Int32>)
Atomically updates the stored value with the results of applying the given function, returning the original value.
Declaration
public static int GetAndUpdate(this ref int value, in ValueFunc<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
ValueFunc<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The original value. |
GetAndUpdate(Int32[], Int64, Func<Int32, Int32>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static int GetAndUpdate(this int[] array, long index, Func<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The original value of the array element. |
GetAndUpdate(Int32[], Int64, ValueFunc<Int32, Int32>)
Atomically updates the array element with the results of applying the given function, returning the original value.
Declaration
public static int GetAndUpdate(this int[] array, long index, in ValueFunc<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The original value of the array element. |
IncrementAndGet(ref Int32)
Atomically increments the referenced value by one.
Declaration
public static int IncrementAndGet(this ref int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Returns
Type | Description |
---|---|
Int32 | Incremented value. |
IncrementAndGet(Int32[], Int64)
Atomically increments the array element by one.
Declaration
public static int IncrementAndGet(this int[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to write into. |
Int64 | index | The index of the element to increment atomically. |
Returns
Type | Description |
---|---|
Int32 | Incremented value. |
SetAndGet(ref Int32, Int32)
Modifies the referenced value atomically.
Declaration
public static int SetAndGet(this ref int value, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
Int32 | update | A new value to be stored into managed pointer. |
Returns
Type | Description |
---|---|
Int32 | A new value passed as argument. |
SetAndGet(Int32[], Int64, Int32)
Modifies the array element atomically.
Declaration
public static int SetAndGet(this int[] array, long index, int update)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of array element to be modified. |
Int32 | update | A new value to be stored as array element. |
Returns
Type | Description |
---|---|
Int32 | The array element after modification. |
UpdateAndGet(ref Int32, Func<Int32, Int32>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static int UpdateAndGet(this ref int value, Func<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
DotNext.Func<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The updated value. |
UpdateAndGet(ref Int32, ValueFunc<Int32, Int32>)
Atomically updates the stored value with the results of applying the given function, returning the updated value.
Declaration
public static int UpdateAndGet(this ref int value, in ValueFunc<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | Reference to a value to be modified. |
ValueFunc<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The updated value. |
UpdateAndGet(Int32[], Int64, Func<Int32, Int32>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static int UpdateAndGet(this int[] array, long index, Func<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
DotNext.Func<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The updated value. |
UpdateAndGet(Int32[], Int64, ValueFunc<Int32, Int32>)
Atomically updates the array element with the results of applying the given function, returning the updated value.
Declaration
public static int UpdateAndGet(this int[] array, long index, in ValueFunc<int, int> updater)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to be modified. |
Int64 | index | The index of the array element to be modified. |
ValueFunc<Int32, Int32> | updater | A side-effect-free function |
Returns
Type | Description |
---|---|
Int32 | The updated value. |
VolatileRead(ref Int32)
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 int VolatileRead(this ref int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The field to read. |
Returns
Type | Description |
---|---|
Int32 | 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(Int32[], Int64)
Performs volatile read of the array element.
Declaration
public static int VolatileRead(this int[] array, long index)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to read from. |
Int64 | index | The array element index. |
Returns
Type | Description |
---|---|
Int32 | The array element. |
VolatileWrite(ref Int32, Int32)
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 int value, int newValue)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The field where the value is written. |
Int32 | newValue | The value to write. The value is written immediately so that it is visible to all processors in the computer. |
VolatileWrite(Int32[], Int64, Int32)
Performs volatile write to the array element.
Declaration
public static void VolatileWrite(this int[] array, long index, int value)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | array | The array to write into. |
Int64 | index | The array element index. |
Int32 | value | The new value of the array element. |