mirror of
https://github.com/wolfpld/tracy
synced 2025-05-03 14:03:52 +00:00
Make sure profiler is initialized only once in delayed init scenario.
This commit is contained in:
parent
9702461b09
commit
c98f1f0b6b
@ -913,17 +913,26 @@ struct ProfilerThreadData
|
||||
# endif
|
||||
};
|
||||
|
||||
static ProfilerData* profilerData;
|
||||
static std::atomic<int> profilerDataLock { 0 };
|
||||
static std::atomic<ProfilerData*> profilerData { nullptr };
|
||||
|
||||
static ProfilerData& GetProfilerData()
|
||||
{
|
||||
// Cannot use magic statics here.
|
||||
if( !profilerData )
|
||||
auto ptr = profilerData.load( std::memory_order_acquire );
|
||||
if( !ptr )
|
||||
{
|
||||
profilerData = (ProfilerData*)malloc( sizeof( ProfilerData ) );
|
||||
new (profilerData) ProfilerData();
|
||||
int expected = 0;
|
||||
while( !profilerDataLock.compare_exchange_strong( expected, 1, std::memory_order_release, std::memory_order_relaxed ) ) { expected = 0; }
|
||||
ptr = profilerData.load( std::memory_order_acquire );
|
||||
if( !ptr )
|
||||
{
|
||||
ptr = (ProfilerData*)malloc( sizeof( ProfilerData ) );
|
||||
new (ptr) ProfilerData();
|
||||
profilerData.store( ptr, std::memory_order_release );
|
||||
}
|
||||
return *profilerData;
|
||||
profilerDataLock.store( 0, std::memory_order_release );
|
||||
}
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
static ProfilerThreadData& GetProfilerThreadData()
|
||||
|
Loading…
x
Reference in New Issue
Block a user