mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Use custom threading wrapper instead of std::thread.
std::thread may perform memory allocation when a thread is created (it does so on MSVC). Tracy heap is managed by its own allocator and this changes prevents accessing application heap.
This commit is contained in:
parent
2f8d3ff5eb
commit
9f28205548
@ -23,6 +23,7 @@
|
||||
#include "TracyAlloc.hpp"
|
||||
#include "TracyScoped.hpp"
|
||||
#include "TracyProfiler.hpp"
|
||||
#include "TracyThread.hpp"
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define DISABLE_LZ4
|
||||
@ -77,6 +78,7 @@ static Profiler init_order(106) s_profiler;
|
||||
#endif
|
||||
|
||||
static Profiler* s_instance = nullptr;
|
||||
static Thread* s_thread = nullptr;
|
||||
|
||||
Profiler::Profiler()
|
||||
: m_mainThread( GetThreadHandle() )
|
||||
@ -94,14 +96,16 @@ Profiler::Profiler()
|
||||
uint32_t cpu;
|
||||
m_timeBegin = GetTime( cpu );
|
||||
|
||||
m_thread = std::thread( [this] { Worker(); } );
|
||||
SetThreadName( m_thread, "Tracy Profiler" );
|
||||
s_thread = (Thread*)tracy_malloc( sizeof( Thread ) );
|
||||
new(s_thread) Thread( LaunchWorker, this );
|
||||
SetThreadName( s_thread->Handle(), "Tracy Profiler" );
|
||||
}
|
||||
|
||||
Profiler::~Profiler()
|
||||
{
|
||||
m_shutdown.store( true, std::memory_order_relaxed );
|
||||
m_thread.join();
|
||||
s_thread->~Thread();
|
||||
tracy_free( s_thread );
|
||||
|
||||
tracy_free( m_buffer );
|
||||
LZ4_freeStream( m_stream );
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <chrono>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
#include "concurrentqueue.h"
|
||||
#include "../common/tracy_lz4.hpp"
|
||||
@ -163,6 +162,7 @@ public:
|
||||
static bool ShouldExit();
|
||||
|
||||
private:
|
||||
static void LaunchWorker( void* ptr ) { ((Profiler*)ptr)->Worker(); }
|
||||
void Worker();
|
||||
|
||||
bool SendData( const char* data, size_t len );
|
||||
@ -180,7 +180,6 @@ private:
|
||||
int64_t m_timeBegin;
|
||||
uint64_t m_mainThread;
|
||||
uint64_t m_epoch;
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_shutdown;
|
||||
std::unique_ptr<Socket> m_sock;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user