public static void AtomicUpdate() { var container = new Atomic <Guid>(); container.GetAndUpdate((in Guid current, out Guid newValue) => newValue = Guid.NewGuid(), out var value); Equal(Guid.Empty, value); NotEqual(Guid.Empty, container.Value); }
public static void ReadWrite() { var container = new Atomic <Guid>(); var value = Guid.NewGuid(); container.Value = value; Equal(value, container.Value); }
public static void CompareAndSet() { var container = new Atomic <Guid>(); True(container.CompareAndSet(Guid.Empty, Guid.NewGuid())); NotEqual(Guid.Empty, container.Value); False(container.CompareAndSet(Guid.Empty, Guid.NewGuid())); NotEqual(Guid.Empty, container.Value); }
public static void AtomicExchange() { var container = new Atomic <Guid>(); Equal(Guid.Empty, container.Value); container.Exchange(Guid.NewGuid(), out var value); Equal(Guid.Empty, value); NotEqual(Guid.Empty, container.Value); }
public static bool CompareAndSet(ref this double value, double expected, double update) => Atomic <double> .Equals(Interlocked.CompareExchange(ref value, update, expected), expected);
public static void VolatileWrite(ref this double value, double newValue) => Atomic.Write(ref value, newValue);
public static double VolatileRead(ref this double value) => Atomic.Read(ref value);
public static IntPtr VolatileRead(ref this IntPtr value) => Atomic.Read(ref value);
public static void VolatileWrite(ref this long value, long newValue) => Atomic.Write(ref value, newValue);
public static long VolatileRead(ref this long value) => Atomic.Read(ref value);
public static void VolatileWrite(ref this int value, int newValue) => Atomic.Write(ref value, newValue);
public static int VolatileRead(ref this int value) => Atomic.Read(ref value);
public static bool CompareAndSet(ref this float value, float expected, float update) => Atomic <float> .Equals(Interlocked.CompareExchange(ref value, update, expected), expected);
public static void VolatileWrite(ref this float value, float newValue) => Atomic.Write(ref value, newValue);
public static float VolatileRead(ref this float value) => Atomic.Read(ref value);
public static E VolatileRead <E>(this ref E value) where E : struct, Enum => Atomic.Read(ref value);