diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 80bc9ae2..4fba38e2 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -11,6 +11,7 @@ #include "../common/TracyProtocol.hpp" #include "../common/TracySocket.hpp" #include "../common/TracySystem.hpp" +#include "concurrentqueue.h" #include "TracyProfiler.hpp" #ifdef _DEBUG @@ -20,10 +21,17 @@ namespace tracy { +static moodycamel::ConcurrentQueue s_queue; + +static moodycamel::ProducerToken& GetToken() +{ + static thread_local moodycamel::ProducerToken token( s_queue ); + return token; +} + extern const char* PointerCheckA; const char* PointerCheckB = "tracy"; - static Profiler* s_instance = nullptr; Profiler::Profiler() @@ -66,7 +74,7 @@ uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data ) item.hdr.type = QueueType::ZoneBegin; item.hdr.id = id; item.zoneBegin = std::move( data ); - s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); + s_queue.enqueue( GetToken(), std::move( item ) ); return id; } @@ -76,7 +84,7 @@ void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data ) item.hdr.type = QueueType::ZoneEnd; item.hdr.id = id; item.zoneEnd = std::move( data ); - s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); + s_queue.enqueue( GetToken(), std::move( item ) ); } void Profiler::FrameMark() @@ -84,12 +92,7 @@ void Profiler::FrameMark() QueueItem item; item.hdr.type = QueueType::FrameMark; item.hdr.id = (uint64_t)GetTime(); - s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); -} - -Profiler* Profiler::Instance() -{ - return s_instance; + s_queue.enqueue( GetToken(), std::move( item ) ); } bool Profiler::ShouldExit() @@ -105,7 +108,7 @@ void Profiler::Worker() tv.tv_sec = 0; tv.tv_usec = 10000; - moodycamel::ConsumerToken token( m_queue ); + moodycamel::ConsumerToken token( s_queue ); ListenSocket listen; listen.Listen( "8086", 8 ); @@ -136,7 +139,7 @@ void Profiler::Worker() if( m_shutdown.load( std::memory_order_relaxed ) ) return; QueueItem item[BulkSize]; - const auto sz = m_queue.try_dequeue_bulk( token, item, BulkSize ); + const auto sz = s_queue.try_dequeue_bulk( token, item, BulkSize ); if( sz > 0 ) { auto buf = m_buffer + m_bufferOffset; diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 72474f38..693fc1d5 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -6,7 +6,6 @@ #include #include -#include "concurrentqueue.h" #include "../common/tracy_lz4.hpp" #include "../common/TracyQueue.hpp" @@ -40,17 +39,9 @@ private: bool SendData( const char* data, size_t len ); bool SendString( uint64_t ptr ); - static Profiler* Instance(); - static moodycamel::ProducerToken& GetToken() - { - static thread_local moodycamel::ProducerToken token( Instance()->m_queue ); - return token; - } - int64_t m_timeBegin; std::thread m_thread; std::atomic m_shutdown; - moodycamel::ConcurrentQueue m_queue; std::atomic m_id; std::unique_ptr m_sock;