예제 #1
0
        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);
        }
예제 #3
0
        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);
        }
예제 #5
0
 public static bool CompareAndSet(ref this double value, double expected, double update)
 => Atomic <double> .Equals(Interlocked.CompareExchange(ref value, update, expected), expected);
예제 #6
0
 public static void VolatileWrite(ref this double value, double newValue) => Atomic.Write(ref value, newValue);
예제 #7
0
 public static double VolatileRead(ref this double value) => Atomic.Read(ref value);
예제 #8
0
 public static IntPtr VolatileRead(ref this IntPtr value) => Atomic.Read(ref value);
예제 #9
0
 public static void VolatileWrite(ref this long value, long newValue) => Atomic.Write(ref value, newValue);
예제 #10
0
 public static long VolatileRead(ref this long value) => Atomic.Read(ref value);
예제 #11
0
 public static void VolatileWrite(ref this int value, int newValue) => Atomic.Write(ref value, newValue);
예제 #12
0
 public static int VolatileRead(ref this int value) => Atomic.Read(ref value);
예제 #13
0
 public static bool CompareAndSet(ref this float value, float expected, float update)
 => Atomic <float> .Equals(Interlocked.CompareExchange(ref value, update, expected), expected);
예제 #14
0
 public static void VolatileWrite(ref this float value, float newValue)
 => Atomic.Write(ref value, newValue);
예제 #15
0
 public static float VolatileRead(ref this float value) => Atomic.Read(ref value);
예제 #16
0
 public static E VolatileRead <E>(this ref E value)
     where E : struct, Enum
 => Atomic.Read(ref value);