From 331693d7f13517946a860f0b9ac3e50ac6677750 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 21 Dec 2018 18:10:29 +0100 Subject: [PATCH] Use proper pattern for acquiring serial lock. This fixes a potential hang during crash handling. Also, lock duration is reduced. --- client/TracyProfiler.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index cccb99bd..38b9086f 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1222,13 +1222,26 @@ void Profiler::ClearQueues( moodycamel::ConsumerToken& token ) for( size_t i=0; i lock( m_serialLock ); + { + bool lockHeld = true; + while( !m_serialLock.try_lock() ) + { + if( m_shutdownManual.load( std::memory_order_relaxed ) ) + { + lockHeld = false; + break; + } + } + for( auto& v : m_serialQueue ) FreeAssociatedMemory( v ); + m_serialQueue.clear(); + if( lockHeld ) + { + m_serialLock.unlock(); + } + } for( auto& v : m_serialDequeue ) FreeAssociatedMemory( v ); m_serialDequeue.clear(); - - for( auto& v : m_serialQueue ) FreeAssociatedMemory( v ); - m_serialQueue.clear(); } Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )