Use proper pattern for acquiring serial lock.

This fixes a potential hang during crash handling. Also, lock duration
is reduced.
This commit is contained in:
Bartosz Taudul 2018-12-21 18:10:29 +01:00
parent 4893bca12b
commit 331693d7f1

View File

@ -1222,13 +1222,26 @@ void Profiler::ClearQueues( moodycamel::ConsumerToken& token )
for( size_t i=0; i<sz; i++ ) FreeAssociatedMemory( m_itemBuf[i] );
}
std::lock_guard<TracyMutex> 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 )