<PackageReference Include="Relativity.Telemetry.Client" Version="9.4.164" />

AtomicLong

public class AtomicLong
Provides lock-free atomic read/write utility for a long value. The atomic classes found in this package are meant to replicate the java.util.concurrent.atomic package in Java by Doug Lea. The two main differences are implicit casting back to the long data type, and the use of a non-volatile inner variable.

The internals of these classes contain wrapped usage of the System.Threading.Interlocked class, which is how we are able to provide atomic operation without the use of locks.

public AtomicLong()

Creates a new AtomicLong instance with an initial value of 0.

public AtomicLong(long value)

Creates a new AtomicLong instance with the initial value provided.

public static long op_Implicit(AtomicLong value)

This operator allows an implicit cast from AtomicLong to long.

public long AddAndGet(long delta)

Atomically adds the given value to the current value.

public bool CompareAndSet(long expected, long result)

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

public long Decrement()

This method decrements the value by 1 and returns the previous value. This is the atomic version of post-decrement.

public long Decrement(long decrementBy)

This method decrements the value by the provided value and returns the previous value. This is the atomic version of post-decrement.

public long Get()

This method returns the current value.

public long GetAndAdd(long delta)

This method atomically adds a delta the value and returns the original value.

public long GetAndSet(long value)

This method atomically sets the value and returns the original value.

public long Increment()

This method increments the value by 1 and returns the previous value. This is the atomic version of post-increment.

public long Increment(long incrementBy)

This method increments the value by the provided value and returns the previous value. This is the atomic version of post-increment.

public long PreDecrement()

This method decrements the value by 1 and returns the new value. This is the atomic version of pre-decrement.

public long PreIncrement()

This method increments the value by 1 and returns the new value. This is the atomic version of pre-increment.

public void Set(long value)

This method sets the current value atomically.