From 2d5d4293a917ba9d83302f9255050c8ed844e0b2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 9 Oct 2021 15:16:36 +0200 Subject: [PATCH] Move thread context check to a separate function. --- client/TracyProfiler.cpp | 22 +++++++++++++--------- client/TracyProfiler.hpp | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index cb116f7b..9f02ab27 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1959,15 +1959,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) const auto sz = GetQueue().try_dequeue_bulk_single( token, [this, &connectionLost] ( const uint32_t& threadId ) { - if( threadId != m_threadCtx ) - { - QueueItem item; - MemWrite( &item.hdr.type, QueueType::ThreadContext ); - MemWrite( &item.threadCtx.thread, threadId ); - if( !AppendData( &item, QueueDataSize[(int)QueueType::ThreadContext] ) ) connectionLost = true; - m_threadCtx = threadId; - m_refTimeThread = 0; - } + if( ThreadCtxCheck( threadId ) == ThreadCtxStatus::ConnectionLost ) connectionLost = true; }, [this, &connectionLost] ( QueueItem* item, size_t sz ) { @@ -2399,6 +2391,18 @@ Profiler::DequeueStatus Profiler::DequeueSerial() return DequeueStatus::DataDequeued; } +Profiler::ThreadCtxStatus Profiler::ThreadCtxCheck( uint32_t threadId ) +{ + if( m_threadCtx == threadId ) return ThreadCtxStatus::Same; + QueueItem item; + MemWrite( &item.hdr.type, QueueType::ThreadContext ); + MemWrite( &item.threadCtx.thread, threadId ); + if( !AppendData( &item, QueueDataSize[(int)QueueType::ThreadContext] ) ) return ThreadCtxStatus::ConnectionLost; + m_threadCtx = threadId; + m_refTimeThread = 0; + return ThreadCtxStatus::Changed; +} + bool Profiler::CommitData() { bool ret = SendData( m_buffer + m_bufferStart, m_bufferOffset - m_bufferStart ); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index bebe86bb..e75aa9af 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -643,6 +643,7 @@ public: private: enum class DequeueStatus { DataDequeued, ConnectionLost, QueueEmpty }; + enum class ThreadCtxStatus { Same, Changed, ConnectionLost }; static void LaunchWorker( void* ptr ) { ((Profiler*)ptr)->Worker(); } void Worker(); @@ -657,6 +658,7 @@ private: DequeueStatus Dequeue( tracy::moodycamel::ConsumerToken& token ); DequeueStatus DequeueContextSwitches( tracy::moodycamel::ConsumerToken& token, int64_t& timeStop ); DequeueStatus DequeueSerial(); + ThreadCtxStatus ThreadCtxCheck( uint32_t threadId ); bool CommitData(); tracy_force_inline bool AppendData( const void* data, size_t len )