From a35e1e7a8c3a837182ca760d99731d5e0467a49e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 2 Jan 2020 23:55:56 +0100 Subject: [PATCH] Keep lock free queue thread local data in one struct. --- client/TracyLfq.cpp | 4 ++-- client/TracyLfq.hpp | 20 +++++++++++++------- client/TracyProfiler.cpp | 3 +-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/client/TracyLfq.cpp b/client/TracyLfq.cpp index 35012fd8..4369a867 100644 --- a/client/TracyLfq.cpp +++ b/client/TracyLfq.cpp @@ -12,8 +12,8 @@ LfqBlock* LfqProducerImpl::NextBlock( LfqBlock* tailBlk ) next->thread = m_thread; tailBlk->next.store( next ); m_tail.store( next ); - lfq_dataEnd = next->dataEnd; - lfq_tail = &next->tail; + lfq.dataEnd = next->dataEnd; + lfq.tail = &next->tail; return next; } diff --git a/client/TracyLfq.hpp b/client/TracyLfq.hpp index 39441d21..d991d938 100644 --- a/client/TracyLfq.hpp +++ b/client/TracyLfq.hpp @@ -59,8 +59,14 @@ public: }; -extern thread_local const char* lfq_dataEnd; -extern thread_local std::atomic* lfq_tail; +struct LfqData +{ + const char* dataEnd; + std::atomic* tail; +}; + +extern thread_local LfqData lfq; + class LfqProducerImpl { @@ -122,9 +128,9 @@ public: static tracy_force_inline char* PrepareNext( char*& nextPtr, size_t sz ) { - auto tail = lfq_tail->load(); + auto tail = lfq.tail->load(); auto np = tail + sz; - if( np <= lfq_dataEnd ) + if( np <= lfq.dataEnd ) { nextPtr = np; return tail; @@ -137,7 +143,7 @@ public: static tracy_force_inline void CommitNext( char* nextPtr ) { - lfq_tail->store( nextPtr ); + lfq.tail->store( nextPtr ); } @@ -331,8 +337,8 @@ tracy_force_inline void LfqProducerImpl::PrepareThread() assert( blk ); assert( blk->next.load() == nullptr ); blk->thread = m_thread; - lfq_dataEnd = blk->dataEnd; - lfq_tail = &blk->tail; + lfq.dataEnd = blk->dataEnd; + lfq.tail = &blk->tail; m_head.store( blk ); m_tail.store( blk ); } diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 0ffa4545..b7eab46a 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -853,8 +853,7 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ ) #endif -thread_local const char* lfq_dataEnd; -thread_local std::atomic* lfq_tail; +thread_local LfqData lfq; static Profiler* s_instance; static Thread* s_thread;