XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFE.SpaceEngineers.AgentBridge

【SpaceEngineer】AI调试插件

公开
关注 0 Fork 0 Star 0
UTF-8
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;
        }
    }
}