internal static IAtomic<T> Get(ref CLRAtomic<T> data) { if(data == null) { data = new CLRAtomic<T>(); } return data._atomic; }
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); }
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)); }
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); }
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)); }
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); }