diff --git a/src/tier0/memstd.cpp b/src/tier0/memstd.cpp index 374df4d1..daba7b4c 100644 --- a/src/tier0/memstd.cpp +++ b/src/tier0/memstd.cpp @@ -13,20 +13,19 @@ //----------------------------------------------------------------------------- // Purpose: initialize the global memory allocator singleton pointer //----------------------------------------------------------------------------- -static bool s_bAllocatorInitialized = false; +static std::atomic_bool s_bAllocatorInitialized = false; static void InitAllocator() { - if (!s_bAllocatorInitialized) - { - s_bAllocatorInitialized = true; - const QWORD imageBase = CModule::GetProcessEnvironmentBlock()->ImageBaseAddress; + if (s_bAllocatorInitialized.exchange(true)) + return; - CreateGlobalMemAlloc = CModule::GetExportedSymbol(imageBase, - "CreateGlobalMemAlloc").RCast(); + const QWORD imageBase = CModule::GetProcessEnvironmentBlock()->ImageBaseAddress; - g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase, - "g_pMemAllocSingleton").DerefSelf().RCast(); - } + CreateGlobalMemAlloc = CModule::GetExportedSymbol(imageBase, + "CreateGlobalMemAlloc").RCast(); + + g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase, + "g_pMemAllocSingleton").DerefSelf().RCast(); } //-----------------------------------------------------------------------------