namespace System.Threading;
/// How a read or write of an `Atomic` orders the others around it (Rust's,
/// C++'s); `SeqCst` unless said.
public enum MemoryOrder { Relaxed, Acquire, Release, AcqRel, SeqCst }
/// A value read and changed by many threads without a lock (Rust's
/// `Atomic*`, .NET's `Interlocked` and `Volatile`): a whole number, a
/// `bool`, a `char`, a reference.
[Intrinsic]
[Threads(ThreadSafety.Guarded)]
public readonly sealed class Atomic<T> {
public Atomic(T value) {}
public readonly T Load(MemoryOrder order = MemoryOrder.SeqCst);
public readonly void Store(T value, MemoryOrder order = MemoryOrder.SeqCst);
/// The value put in, the one there given back.
public readonly T Exchange(T value, MemoryOrder order = MemoryOrder.SeqCst);
/// Puts `value` in if `expected` is there: what was there.
public readonly T CompareExchange(T expected, T value, MemoryOrder order = MemoryOrder.SeqCst);
/// A whole number's sum with `delta`, kept: the new value.
public readonly T Add(T delta, MemoryOrder order = MemoryOrder.SeqCst);
public readonly T Increment(MemoryOrder order = MemoryOrder.SeqCst);
public readonly T Decrement(MemoryOrder order = MemoryOrder.SeqCst);
/// The value changed by `change`, retried until no other thread came
/// between: the new value.
public readonly T Update(Func<T, T> change);
}