From b371003336e8c034c094fe5374bb511be39871d7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 20 Aug 2018 21:49:23 +0200 Subject: [PATCH] In case of manual shutdown, don't wait for lock. All threads are freezed at this point, nothing will release it. --- client/TracyProfiler.cpp | 16 ++++++++++++++-- client/TracyProfiler.hpp | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index bd4284dd..72061753 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -743,6 +743,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_shutdownManual( false ) , m_shutdownFinished( false ) , m_sock( nullptr ) , m_noExit( false ) @@ -1129,9 +1130,20 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) Profiler::DequeueStatus Profiler::DequeueSerial() { { - while( !m_serialLock.try_lock() ) {} + bool lockHeld = true; + while( !m_serialLock.try_lock() ) + { + if( m_shutdownManual.load( std::memory_order_relaxed ) ) + { + lockHeld = false; + break; + } + } m_serialQueue.swap( m_serialDequeue ); - m_serialLock.unlock(); + if( lockHeld ) + { + m_serialLock.unlock(); + } } const auto sz = m_serialDequeue.size(); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 8220caf1..4e9491f5 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -342,7 +342,7 @@ public: } #endif - void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); } + void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); m_shutdownManual.store( true, std::memory_order_relaxed ); } bool HasShutdownFinished() const { return m_shutdownFinished.load( std::memory_order_relaxed ); } private: @@ -424,6 +424,7 @@ private: uint64_t m_mainThread; uint64_t m_epoch; std::atomic m_shutdown; + std::atomic m_shutdownManual; std::atomic m_shutdownFinished; Socket* m_sock; bool m_noExit;