diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 69edca77..6318ee13 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -400,6 +400,7 @@ Profiler::Profiler() , m_mainThread( GetThreadHandle() ) , m_epoch( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() ) , m_shutdown( false ) + , m_shutdownFinished( false ) , m_sock( nullptr ) , m_noExit( false ) , m_stream( LZ4_createStream() ) @@ -514,7 +515,11 @@ void Profiler::Worker() for(;;) { #ifndef TRACY_NO_EXIT - if( !m_noExit && ShouldExit() ) return; + if( !m_noExit && ShouldExit() ) + { + m_shutdownFinished.store( true, std::memory_order_relaxed ); + return; + } #endif m_sock = listen.Accept(); if( m_sock ) break; @@ -613,7 +618,11 @@ void Profiler::Worker() QueueItem terminate; MemWrite( &terminate.hdr.type, QueueType::Terminate ); - if( !SendData( (const char*)&terminate, 1 ) ) return; + if( !SendData( (const char*)&terminate, 1 ) ) + { + m_shutdownFinished.store( true, std::memory_order_relaxed ); + return; + } for(;;) { if( m_sock->HasData() ) @@ -623,6 +632,7 @@ void Profiler::Worker() if( !HandleServerQuery() ) { if( m_bufferOffset != m_bufferStart ) CommitData(); + m_shutdownFinished.store( true, std::memory_order_relaxed ); return; } } @@ -630,7 +640,11 @@ void Profiler::Worker() while( DequeueSerial() == Success ) {} if( m_bufferOffset != m_bufferStart ) { - if( !CommitData() ) return; + if( !CommitData() ) + { + m_shutdownFinished.store( true, std::memory_order_relaxed ); + return; + } } } else diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 06ac93f7..8220caf1 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -342,6 +342,9 @@ public: } #endif + void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); } + bool HasShutdownFinished() const { return m_shutdownFinished.load( std::memory_order_relaxed ); } + private: enum DequeueStatus { Success, ConnectionLost, QueueEmpty }; @@ -421,6 +424,7 @@ private: uint64_t m_mainThread; uint64_t m_epoch; std::atomic m_shutdown; + std::atomic m_shutdownFinished; Socket* m_sock; bool m_noExit;