using System.Threading; namespace XFE.SeAgent.Plugin.Performance { public static class AtomicMaximum { // Same atomic-max result and return value as the engine. A value that is // already high enough needs only an acquire read, not ownership of the // shared cache line on every render worker. public static int Update(ref int storage, int value) { int current = Volatile.Read(ref storage); while (current < value) { int observed = Interlocked.CompareExchange(ref storage, value, current); if (observed == current) return current; current = observed; } return current; } } }