mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Add TracyIsStarted
When using TRACY_MANUAL_LIFETIME, calling most Tracy functions before starting the profiler results in an assertion. Notably, even TracyIsConnected is affected. There is, however, no function to check if the profiler had already started. This commit adds such a function.
This commit is contained in:
@@ -1142,12 +1142,14 @@ thread_local bool RpThreadShutdown = false;
|
||||
# ifdef TRACY_MANUAL_LIFETIME
|
||||
ProfilerData* s_profilerData = nullptr;
|
||||
static ProfilerThreadData& GetProfilerThreadData();
|
||||
static std::atomic<bool> s_isProfilerStarted { false };
|
||||
TRACY_API void StartupProfiler()
|
||||
{
|
||||
s_profilerData = (ProfilerData*)tracy_malloc( sizeof( ProfilerData ) );
|
||||
new (s_profilerData) ProfilerData();
|
||||
s_profilerData->profiler.SpawnWorkerThreads();
|
||||
GetProfilerThreadData().token = ProducerWrapper( *s_profilerData );
|
||||
s_isProfilerStarted.store( true, std::memory_order_seq_cst );
|
||||
}
|
||||
static ProfilerData& GetProfilerData()
|
||||
{
|
||||
@@ -1156,6 +1158,7 @@ static ProfilerData& GetProfilerData()
|
||||
}
|
||||
TRACY_API void ShutdownProfiler()
|
||||
{
|
||||
s_isProfilerStarted.store( false, std::memory_order_seq_cst );
|
||||
s_profilerData->~ProfilerData();
|
||||
tracy_free( s_profilerData );
|
||||
s_profilerData = nullptr;
|
||||
@@ -1163,6 +1166,10 @@ TRACY_API void ShutdownProfiler()
|
||||
RpThreadInitDone = false;
|
||||
RpInitDone.store( 0, std::memory_order_release );
|
||||
}
|
||||
TRACY_API bool IsProfilerStarted()
|
||||
{
|
||||
return s_isProfilerStarted.load( std::memory_order_seq_cst );
|
||||
}
|
||||
# else
|
||||
static std::atomic<int> profilerDataLock { 0 };
|
||||
static std::atomic<ProfilerData*> profilerData { nullptr };
|
||||
@@ -4439,6 +4446,11 @@ TRACY_API void ___tracy_shutdown_profiler( void )
|
||||
{
|
||||
tracy::ShutdownProfiler();
|
||||
}
|
||||
|
||||
TRACY_API int ___tracy_profiler_started( void )
|
||||
{
|
||||
return tracy::s_isProfilerStarted.load( std::memory_order_seq_cst );
|
||||
}
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user