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