DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.0.0" />

 AtomicInt32

public static class AtomicInt32
Various atomic operations for Int32 data type accessible as extension methods.
public static int AccumulateAndGet(this ref int value, int x, Func<int, int, int> accumulator)

Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.

public static int AccumulateAndGet(this ref int value, int x, method accumulator)

public static int AddAndGet(this ref int value, int operand)

Adds two 32-bit integers and replaces referenced integer with the sum, as an atomic operation.

public static int BitwiseAndAndGet(this ref int value, int operand)

Bitwise "ands" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static int BitwiseOrAndGet(this ref int value, int operand)

Bitwise "ors" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static int BitwiseXorAndGet(this ref int value, int operand)

Bitwise "xors" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static bool CompareAndSet(this ref int value, int expected, int update)

Atomically sets the referenced value to the given updated value if the current value == the expected value.

public static int DecrementAndGet(this ref int value)

Atomically decrements the referenced value by one.

public static int GetAndAccumulate(this ref int value, int x, Func<int, int, int> accumulator)

Atomically updates the current value with the results of applying the given function to the current and given values, returning the original value.

public static int GetAndAccumulate(this ref int value, int x, method accumulator)

public static int GetAndAdd(this ref int value, int operand)

Adds two 32-bit integers and replaces referenced integer with the sum, as an atomic operation.

public static int GetAndBitwiseAnd(this ref int value, int operand)

Bitwise "ands" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static int GetAndBitwiseOr(this ref int value, int operand)

Bitwise "ors" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static int GetAndBitwiseXor(this ref int value, int operand)

Bitwise "xors" two 32-bit integers and replaces referenced integer with the result, as an atomic operation.

public static int GetAndSet(this ref int value, int update)

Modifies the referenced value atomically.

public static int GetAndUpdate(this ref int value, Func<int, int> updater)

Atomically updates the stored value with the results of applying the given function, returning the original value.

public static int GetAndUpdate(this ref int value, method updater)

public static int IncrementAndGet(this ref int value)

Atomically increments the referenced value by one.

public static int SetAndGet(this ref int value, int update)

Modifies the referenced value atomically.

public static int UpdateAndGet(this ref int value, Func<int, int> updater)

Atomically updates the stored value with the results of applying the given function, returning the updated value.

public static int UpdateAndGet(this ref int value, method updater)

public static int VolatileRead(this ref int value)

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.

public static void VolatileWrite(this ref int value, int newValue)

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.