From 860e0e180966fb688d100f75d01136383a7fed6e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 1 Apr 2018 19:53:24 +0200 Subject: [PATCH] Store memory operations in the serial queue. --- client/TracyProfiler.hpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index f03c51d2..eb8b7057 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -193,29 +193,31 @@ public: static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) { - Magic magic; - auto& token = s_token.ptr; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); + const auto time = GetTime(); + const auto thread = GetThreadHandle(); + + s_profiler.m_serialLock.lock(); + auto item = s_profiler.m_serialQueue.push_next(); MemWrite( &item->hdr.type, QueueType::MemAlloc ); - MemWrite( &item->memAlloc.time, GetTime() ); - MemWrite( &item->memAlloc.thread, GetThreadHandle() ); + MemWrite( &item->memAlloc.time, time ); + MemWrite( &item->memAlloc.thread, thread ); MemWrite( &item->memAlloc.ptr, (uint64_t)ptr ); memcpy( &item->memAlloc.size, &size, 6 ); - tail.store( magic + 1, std::memory_order_release ); + s_profiler.m_serialLock.unlock(); } static tracy_force_inline void MemFree( const void* ptr ) { - Magic magic; - auto& token = s_token.ptr; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); + const auto time = GetTime(); + const auto thread = GetThreadHandle(); + + s_profiler.m_serialLock.lock(); + auto item = s_profiler.m_serialQueue.push_next(); MemWrite( &item->hdr.type, QueueType::MemFree ); - MemWrite( &item->memFree.time, GetTime() ); - MemWrite( &item->memFree.thread, GetThreadHandle() ); + MemWrite( &item->memFree.time, time ); + MemWrite( &item->memFree.thread, thread ); MemWrite( &item->memFree.ptr, (uint64_t)ptr ); - tail.store( magic + 1, std::memory_order_release ); + s_profiler.m_serialLock.unlock(); } static bool ShouldExit();