diff --git a/TracyC.h b/TracyC.h index 9df1b651..ea216e31 100644 --- a/TracyC.h +++ b/TracyC.h @@ -81,6 +81,7 @@ struct ___tracy_c_zone_context // This struct, as visible to user, is immutable, so treat it as if const was declared here. typedef /*const*/ struct ___tracy_c_zone_context TracyCZoneCtx; +TRACY_API void ___tracy_init_thread(void); TRACY_API uint64_t ___tracy_alloc_srcloc( uint32_t line, const char* source, const char* function ); TRACY_API uint64_t ___tracy_alloc_srcloc_name( uint32_t line, const char* source, const char* function, const char* name, size_t nameSz ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index ba0e72f2..af0bf62e 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -3068,6 +3068,13 @@ TRACY_API void ___tracy_emit_message_appinfo( const char* txt, size_t size ) { t TRACY_API uint64_t ___tracy_alloc_srcloc( uint32_t line, const char* source, const char* function ) { return tracy::Profiler::AllocSourceLocation( line, source, function ); } TRACY_API uint64_t ___tracy_alloc_srcloc_name( uint32_t line, const char* source, const char* function, const char* name, size_t nameSz ) { return tracy::Profiler::AllocSourceLocation( line, source, function, name, nameSz ); } +// thread_locals are not initialized on thread creation. At least on GNU/Linux. Instead they are +// initialized on their first ODR-use. This means that the allocator is not automagically +// initialized every time a thread is created. As thus, expose to the C API users a simple API to +// call every time they create a thread. Here we can then put all sorts of per-thread +// initialization. +TRACY_API void ___tracy_init_thread(void) { (void)tracy::s_rpmalloc_thread_init; } + #ifdef __cplusplus } #endif diff --git a/manual/tracy.tex b/manual/tracy.tex index 793bc7c8..3cea67a7 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -1477,6 +1477,9 @@ couleur=black!5, logo=\bcbombe ]{Important} Since you are directly calling the profiler functions here, you will need to take care of manually disabling the code, if the \texttt{TRACY\_ENABLE} macro is not defined. + +Additionally, make sure you have called \texttt{\_\_\_tracy\_init\_thread} before calling the +\textttt{alloc} functions for the first time on a new non-main thread. \end{bclogo} \subsubsection{Memory profiling}