diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index a272aaaf..a6da7cc7 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -20,11 +20,11 @@ public: { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockAnnounce; item->lockAnnounce.id = m_id; item->lockAnnounce.srcloc = (uint64_t)srcloc; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } Lockable( const Lockable& ) = delete; @@ -37,12 +37,12 @@ public: { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockWait; item->lockWait.id = m_id; item->lockWait.thread = thread; item->lockWait.time = Profiler::GetTime( cpu ); - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } m_lockable.lock(); @@ -50,12 +50,12 @@ public: { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockObtain; item->lockObtain.id = m_id; item->lockObtain.thread = thread; item->lockObtain.time = Profiler::GetTime( cpu ); - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } } @@ -66,12 +66,12 @@ public: uint32_t cpu; Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockRelease; item->lockRelease.id = m_id; item->lockRelease.thread = GetThreadHandle(); item->lockRelease.time = Profiler::GetTime( cpu ); - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } tracy_force_inline bool try_lock() @@ -82,12 +82,12 @@ public: uint32_t cpu; Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockObtain; item->lockObtain.id = (uint64_t)&m_lockable; item->lockObtain.thread = GetThreadHandle(); item->lockObtain.time = Profiler::GetTime( cpu ); - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } return ret; } @@ -96,12 +96,12 @@ public: { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::LockMark; item->lockMark.id = m_id; item->lockMark.thread = GetThreadHandle(); item->lockMark.srcloc = (uint64_t)srcloc; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } private: diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 0ff4b6a8..ffbd1bca 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -54,13 +54,14 @@ static const char* GetProcessName() enum { QueuePrealloc = 256 * 1024 }; -moodycamel::ConcurrentQueue init_order(101) s_queue( QueueItemSize * QueuePrealloc ); -thread_local moodycamel::ProducerToken init_order(102) s_token( s_queue ); +static moodycamel::ConcurrentQueue init_order(101) s_queue( QueueItemSize * QueuePrealloc ); +static thread_local moodycamel::ProducerToken init_order(102) s_token_detail( s_queue ); +thread_local moodycamel::ConcurrentQueue::ExplicitProducer* init_order(103) s_token = s_queue.get_explicit_producer( s_token_detail ); std::atomic s_id( 0 ); #ifndef TRACY_DISABLE -static Profiler init_order(103) s_profiler; +static Profiler init_order(104) s_profiler; #endif static Profiler* s_instance = nullptr; @@ -226,7 +227,7 @@ void Profiler::SendSourceLocation( uint64_t ptr ) item.srcloc.function = (uint64_t)srcloc->function; item.srcloc.line = srcloc->line; item.srcloc.color = srcloc->color; - s_queue.enqueue( s_token, std::move( item ) ); + s_token->enqueue( std::move( item ) ); } bool Profiler::HandleServerQuery() @@ -311,26 +312,27 @@ void Profiler::CalibrateDelay() static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" ); uint32_t cpu; - moodycamel::ProducerToken ptoken( s_queue ); + moodycamel::ProducerToken ptoken_detail( s_queue ); + moodycamel::ConcurrentQueue::ExplicitProducer* ptoken = s_queue.get_explicit_producer( ptoken_detail ); for( int i=0; ienqueue_begin( magic ); item->hdr.type = QueueType::ZoneBegin; item->zoneBegin.thread = GetThreadHandle(); item->zoneBegin.time = GetTime( item->zoneBegin.cpu ); item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location; - s_queue.enqueue_finish( ptoken, magic ); + ptoken->enqueue_finish( magic ); } { Magic magic; - auto item = s_queue.enqueue_begin( ptoken, magic ); + auto item = ptoken->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneEnd; item->zoneEnd.thread = 0; item->zoneEnd.time = GetTime( item->zoneEnd.cpu ); - s_queue.enqueue_finish( ptoken, magic ); + ptoken->enqueue_finish( magic ); } } const auto f0 = GetTime( cpu ); @@ -345,20 +347,20 @@ void Profiler::CalibrateDelay() static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; { Magic magic; - auto item = s_queue.enqueue_begin( ptoken, magic ); + auto item = ptoken->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneBegin; item->zoneBegin.thread = GetThreadHandle(); item->zoneBegin.time = GetTime( item->zoneBegin.cpu ); item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location; - s_queue.enqueue_finish( ptoken, magic ); + ptoken->enqueue_finish( magic ); } { Magic magic; - auto item = s_queue.enqueue_begin( ptoken, magic ); + auto item = ptoken->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneEnd; item->zoneEnd.thread = 0; item->zoneEnd.time = GetTime( item->zoneEnd.cpu ); - s_queue.enqueue_finish( ptoken, magic ); + ptoken->enqueue_finish( magic ); } } const auto t1 = GetTime( cpu ); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 18b9063d..8219b994 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -31,8 +31,7 @@ struct SourceLocation uint32_t color; }; -extern moodycamel::ConcurrentQueue s_queue; -extern thread_local moodycamel::ProducerToken s_token; +extern thread_local moodycamel::ConcurrentQueue::ExplicitProducer* s_token; using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t; @@ -71,10 +70,10 @@ public: uint32_t cpu; Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::FrameMarkMsg; item->frameMark.time = GetTime( cpu ); - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } static bool ShouldExit(); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 58f4646d..5987a61e 100644 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -19,23 +19,23 @@ public: m_thread = thread; Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneBegin; item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu ); item->zoneBegin.thread = thread; item->zoneBegin.srcloc = (uint64_t)srcloc; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } tracy_force_inline ~ScopedZone() { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneEnd; item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu ); item->zoneEnd.thread = m_thread; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } tracy_force_inline void Text( const char* txt, size_t size ) @@ -45,22 +45,22 @@ public: memcpy( ptr, txt, size ); ptr[size] = '\0'; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneText; item->zoneText.thread = m_thread; item->zoneText.text = (uint64_t)ptr; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } tracy_force_inline void Name( const char* name ) { Magic magic; auto& token = s_token; - auto item = s_queue.enqueue_begin( token, magic ); + auto item = token->enqueue_begin( magic ); item->hdr.type = QueueType::ZoneName; item->zoneName.thread = m_thread; item->zoneName.name = (uint64_t)name; - s_queue.enqueue_finish( token, magic ); + token->enqueue_finish( magic ); } private: diff --git a/client/concurrentqueue.h b/client/concurrentqueue.h index 0f8c3d30..e1e9cce3 100644 --- a/client/concurrentqueue.h +++ b/client/concurrentqueue.h @@ -262,6 +262,8 @@ namespace details { } max_align_t; } +enum AllocationMode { CanAlloc, CannotAlloc }; + // Default traits for the ConcurrentQueue. To change some of the // traits without re-implementing all of them, inherit from this // struct and shadow the declarations you wish to be different; @@ -1287,7 +1289,6 @@ private: friend struct ExplicitProducer; friend class ConcurrentQueueTests; - enum AllocationMode { CanAlloc, CannotAlloc }; /////////////////////////////// @@ -1717,10 +1718,10 @@ private: }; + public: /////////////////////////// // Explicit queue /////////////////////////// - struct ExplicitProducer : public ProducerBase { explicit ExplicitProducer(ConcurrentQueue* parent) : @@ -2370,7 +2371,7 @@ private: return 0; } - + private: struct BlockIndexEntry { @@ -2447,6 +2448,12 @@ private: #endif }; + ExplicitProducer* get_explicit_producer(producer_token_t const& token) + { + return static_cast(token.producer); + } + + private: ////////////////////////////////// // Implicit queue