Update platformMemory.cpp

undo experimental changes to platformMemory.cpp
This commit is contained in:
marauder2k7 2025-05-20 10:11:25 +01:00
parent 700bf32a2a
commit 4a1019619f

View file

@ -30,9 +30,6 @@
#include "platform/threads/mutex.h"
#include "core/module.h"
#include <mutex>
#include <atomic>
#ifdef _WIN32
#include <windows.h>
#include <dbghelp.h>
@ -60,7 +57,7 @@
#ifdef TORQUE_MULTITHREAD
void* gMemMutex = NULL;
#endif
//-------------------------------------- Make sure we don't have the define set
#ifdef new
#undef new
@ -75,11 +72,9 @@ namespace Memory
static const U32 MaxAllocs = 10240;
static MemInfo allocList[MaxAllocs];
static std::atomic<U32> allocCount{ 0 };
static std::atomic<U32> currentAllocId{ 0 };
static U32 allocCount = 0;
static U32 currentAllocId = 0;
static bool initialized = false;
static std::mutex memMutex; // Use shared_mutex if you need more granularity
char gLogFilename[256] = { 0 };
bool gStackTrace = true;
bool gFromScript = false;
@ -101,7 +96,6 @@ namespace Memory
void init()
{
std::lock_guard<std::mutex> lock(memMutex);
if (initialized) return;
std::memset(allocList, 0, sizeof(allocList));
std::memset(memLog, 0, sizeof(memLog));
@ -119,11 +113,8 @@ namespace Memory
void shutdown()
{
std::lock_guard<std::mutex> lock(memMutex);
if (!initialized) return;
initialized = false; // stop memlog from running now.
FILE* log = std::fopen(gLogFilename, "w");
if (!log)
return;
@ -227,7 +218,6 @@ namespace Memory
void checkPtr(void* ptr)
{
std::lock_guard<std::mutex> lock(memMutex);
for (U32 i = 0; i < allocCount; ++i)
if (allocList[i].ptr == ptr)
return;
@ -247,7 +237,6 @@ namespace Memory
if (!initialized || allocCount >= MaxAllocs)
return ptr;
std::lock_guard<std::mutex> lock(memMutex);
MemInfo& info = allocList[allocCount++];
info.ptr = ptr;
info.size = size;
@ -261,7 +250,7 @@ namespace Memory
#ifdef _WIN32
info.backtraceSize = CaptureStackBackTrace(0, 16, info.backtracePtrs, nullptr);
#else
info.backtraceSize = backtrace(info.backtracePtrs, 16);
info.backtraceSize = backtrace(info.backtracePtrs, MaxBacktraceDepth);
#endif
}
@ -279,8 +268,6 @@ namespace Memory
return;
}
std::lock_guard<std::mutex> lock(memMutex);
for (U32 i = 0; i < allocCount; ++i)
{
if (allocList[i].ptr == ptr)
@ -301,7 +288,6 @@ namespace Memory
if (!ptr || !initialized)
return;
std::lock_guard<std::mutex> lock(memMutex);
for (U32 i = 0; i < allocCount; ++i)
{
if (allocList[i].ptr == ptr)
@ -331,7 +317,6 @@ namespace Memory
if (!newPtr)
return nullptr;
std::lock_guard<std::mutex> lock(memMutex);
// Update existing record
for (U32 i = 0; i < allocCount; ++i)
@ -453,7 +438,7 @@ void dFree(void* in_pFree)
void* dRealloc_r(void* in_pResize, dsize_t in_size, const char* fileName, const dsize_t line)
{
return realloc(in_pResize,in_size);
return realloc(in_pResize, in_size);
}
#endif