mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Tier0: make sure the memalloc singleton initializer is thread safe
Only enter code if the atomic exchange was performed.
This commit is contained in:
parent
716a3efa0c
commit
6827d1ed02
@ -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<CStdMemAlloc* (*)(void)>();
|
||||
const QWORD imageBase = CModule::GetProcessEnvironmentBlock()->ImageBaseAddress;
|
||||
|
||||
g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase,
|
||||
"g_pMemAllocSingleton").DerefSelf().RCast<CStdMemAlloc*>();
|
||||
}
|
||||
CreateGlobalMemAlloc = CModule::GetExportedSymbol(imageBase,
|
||||
"CreateGlobalMemAlloc").RCast<CStdMemAlloc * (*)(void)>();
|
||||
|
||||
g_pMemAllocSingleton = CModule::GetExportedSymbol(imageBase,
|
||||
"g_pMemAllocSingleton").DerefSelf().RCast<CStdMemAlloc*>();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user