Tier0: make sure the memalloc singleton initializer is thread safe

Only enter code if the atomic exchange was performed.
This commit is contained in:
Kawe Mazidjatari 2025-01-09 16:56:48 +01:00
parent 716a3efa0c
commit 6827d1ed02

View File

@ -13,12 +13,12 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: initialize the global memory allocator singleton pointer // Purpose: initialize the global memory allocator singleton pointer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static bool s_bAllocatorInitialized = false; static std::atomic_bool s_bAllocatorInitialized = false;
static void InitAllocator() static void InitAllocator()
{ {
if (!s_bAllocatorInitialized) if (s_bAllocatorInitialized.exchange(true))
{ return;
s_bAllocatorInitialized = true;
const QWORD imageBase = CModule::GetProcessEnvironmentBlock()->ImageBaseAddress; const QWORD imageBase = CModule::GetProcessEnvironmentBlock()->ImageBaseAddress;
CreateGlobalMemAlloc = CModule::GetExportedSymbol(imageBase, CreateGlobalMemAlloc = CModule::GetExportedSymbol(imageBase,
@ -27,7 +27,6 @@ static void InitAllocator()
g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase, g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase,
"g_pMemAllocSingleton").DerefSelf().RCast<CStdMemAlloc*>(); "g_pMemAllocSingleton").DerefSelf().RCast<CStdMemAlloc*>();
} }
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: new/delete operator override // Purpose: new/delete operator override