Move thread context check to a separate function.

This commit is contained in:
Bartosz Taudul 2021-10-09 15:16:36 +02:00
parent 13acec38f7
commit 2d5d4293a9
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 15 additions and 9 deletions

View File

@ -1959,15 +1959,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
const auto sz = GetQueue().try_dequeue_bulk_single( token, const auto sz = GetQueue().try_dequeue_bulk_single( token,
[this, &connectionLost] ( const uint32_t& threadId ) [this, &connectionLost] ( const uint32_t& threadId )
{ {
if( threadId != m_threadCtx ) if( ThreadCtxCheck( threadId ) == ThreadCtxStatus::ConnectionLost ) connectionLost = true;
{
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;
}
}, },
[this, &connectionLost] ( QueueItem* item, size_t sz ) [this, &connectionLost] ( QueueItem* item, size_t sz )
{ {
@ -2399,6 +2391,18 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
return DequeueStatus::DataDequeued; 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 Profiler::CommitData()
{ {
bool ret = SendData( m_buffer + m_bufferStart, m_bufferOffset - m_bufferStart ); bool ret = SendData( m_buffer + m_bufferStart, m_bufferOffset - m_bufferStart );

View File

@ -643,6 +643,7 @@ public:
private: private:
enum class DequeueStatus { DataDequeued, ConnectionLost, QueueEmpty }; enum class DequeueStatus { DataDequeued, ConnectionLost, QueueEmpty };
enum class ThreadCtxStatus { Same, Changed, ConnectionLost };
static void LaunchWorker( void* ptr ) { ((Profiler*)ptr)->Worker(); } static void LaunchWorker( void* ptr ) { ((Profiler*)ptr)->Worker(); }
void Worker(); void Worker();
@ -657,6 +658,7 @@ private:
DequeueStatus Dequeue( tracy::moodycamel::ConsumerToken& token ); DequeueStatus Dequeue( tracy::moodycamel::ConsumerToken& token );
DequeueStatus DequeueContextSwitches( tracy::moodycamel::ConsumerToken& token, int64_t& timeStop ); DequeueStatus DequeueContextSwitches( tracy::moodycamel::ConsumerToken& token, int64_t& timeStop );
DequeueStatus DequeueSerial(); DequeueStatus DequeueSerial();
ThreadCtxStatus ThreadCtxCheck( uint32_t threadId );
bool CommitData(); bool CommitData();
tracy_force_inline bool AppendData( const void* data, size_t len ) tracy_force_inline bool AppendData( const void* data, size_t len )