mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Hide implementation details wrt concurrent queue.
This commit is contained in:
parent
2f7fa20e34
commit
9d2fef2f11
@ -11,6 +11,7 @@
|
||||
#include "../common/TracyProtocol.hpp"
|
||||
#include "../common/TracySocket.hpp"
|
||||
#include "../common/TracySystem.hpp"
|
||||
#include "concurrentqueue.h"
|
||||
#include "TracyProfiler.hpp"
|
||||
|
||||
#ifdef _DEBUG
|
||||
@ -20,10 +21,17 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
static moodycamel::ConcurrentQueue<QueueItem> s_queue;
|
||||
|
||||
static moodycamel::ProducerToken& GetToken()
|
||||
{
|
||||
static thread_local moodycamel::ProducerToken token( s_queue );
|
||||
return token;
|
||||
}
|
||||
|
||||
extern const char* PointerCheckA;
|
||||
const char* PointerCheckB = "tracy";
|
||||
|
||||
|
||||
static Profiler* s_instance = nullptr;
|
||||
|
||||
Profiler::Profiler()
|
||||
@ -66,7 +74,7 @@ uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data )
|
||||
item.hdr.type = QueueType::ZoneBegin;
|
||||
item.hdr.id = id;
|
||||
item.zoneBegin = std::move( data );
|
||||
s_instance->m_queue.enqueue( GetToken(), std::move( item ) );
|
||||
s_queue.enqueue( GetToken(), std::move( item ) );
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -76,7 +84,7 @@ void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data )
|
||||
item.hdr.type = QueueType::ZoneEnd;
|
||||
item.hdr.id = id;
|
||||
item.zoneEnd = std::move( data );
|
||||
s_instance->m_queue.enqueue( GetToken(), std::move( item ) );
|
||||
s_queue.enqueue( GetToken(), std::move( item ) );
|
||||
}
|
||||
|
||||
void Profiler::FrameMark()
|
||||
@ -84,12 +92,7 @@ void Profiler::FrameMark()
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::FrameMark;
|
||||
item.hdr.id = (uint64_t)GetTime();
|
||||
s_instance->m_queue.enqueue( GetToken(), std::move( item ) );
|
||||
}
|
||||
|
||||
Profiler* Profiler::Instance()
|
||||
{
|
||||
return s_instance;
|
||||
s_queue.enqueue( GetToken(), std::move( item ) );
|
||||
}
|
||||
|
||||
bool Profiler::ShouldExit()
|
||||
@ -105,7 +108,7 @@ void Profiler::Worker()
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 10000;
|
||||
|
||||
moodycamel::ConsumerToken token( m_queue );
|
||||
moodycamel::ConsumerToken token( s_queue );
|
||||
|
||||
ListenSocket listen;
|
||||
listen.Listen( "8086", 8 );
|
||||
@ -136,7 +139,7 @@ void Profiler::Worker()
|
||||
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
|
||||
|
||||
QueueItem item[BulkSize];
|
||||
const auto sz = m_queue.try_dequeue_bulk( token, item, BulkSize );
|
||||
const auto sz = s_queue.try_dequeue_bulk( token, item, BulkSize );
|
||||
if( sz > 0 )
|
||||
{
|
||||
auto buf = m_buffer + m_bufferOffset;
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <stdint.h>
|
||||
#include <thread>
|
||||
|
||||
#include "concurrentqueue.h"
|
||||
#include "../common/tracy_lz4.hpp"
|
||||
#include "../common/TracyQueue.hpp"
|
||||
|
||||
@ -40,17 +39,9 @@ private:
|
||||
bool SendData( const char* data, size_t len );
|
||||
bool SendString( uint64_t ptr );
|
||||
|
||||
static Profiler* Instance();
|
||||
static moodycamel::ProducerToken& GetToken()
|
||||
{
|
||||
static thread_local moodycamel::ProducerToken token( Instance()->m_queue );
|
||||
return token;
|
||||
}
|
||||
|
||||
int64_t m_timeBegin;
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_shutdown;
|
||||
moodycamel::ConcurrentQueue<QueueItem> m_queue;
|
||||
std::atomic<uint64_t> m_id;
|
||||
std::unique_ptr<Socket> m_sock;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user