Exemple #1
0
 internal static IAtomic<T> Get(ref CLRAtomic<T> data)
 {
     if(data == null)
     {
         data = new CLRAtomic<T>();
     }
     return data._atomic;
 }
Exemple #2
0
        public static void Write <T>(ref CLRAtomic <T> data, T newValue, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) where T : class
        {
            // All writes are release in the CLR, but specify them as Relaxed anyway.
            // This is a compromise that feels OK, it means that LiveAtomics won't use Volatile unnecessarily,
            // and it's probably very bad practise to rely upon stores being release in the CLR implicitly in the first place.
            var atomic = CLRAtomic <T> .Get(ref data);

            atomic.Store(newValue, MemoryOrder.Relaxed, memberName, sourceFilePath, sourceLineNumber);
        }
Exemple #3
0
        public static T Read <T>(ref CLRAtomic <T> data, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) where T : class
        {
            var atomic = CLRAtomic <T> .Get(ref data);

            return(atomic.Load(MemoryOrder.Relaxed, memberName, sourceFilePath, sourceLineNumber));
        }
Exemple #4
0
        public static void Write <T>(ref CLRAtomic <T> data, T newValue, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) where T : class
        {
            var atomic = CLRAtomic <T> .Get(ref data);

            atomic.Store(newValue, MemoryOrder.Release, memberName, sourceFilePath, sourceLineNumber);
        }
Exemple #5
0
        public static bool CompareExchange <T>(ref CLRAtomic <T> data, T newData, T comparand, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) where T : class
        {
            var atomic = CLRAtomic <T> .Get(ref data);

            return(atomic.CompareExchange(newData, comparand, MemoryOrder.SequentiallyConsistent));
        }
Exemple #6
0
        public static void Exchange <T>(ref CLRAtomic <T> data, T newData, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) where T : class
        {
            var atomic = CLRAtomic <T> .Get(ref data);

            atomic.Exchange(newData, MemoryOrder.SequentiallyConsistent, memberName, sourceFilePath, sourceLineNumber);
        }