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
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static ProfilerData* profilerData;
|
static std::atomic<int> profilerDataLock { 0 };
|
||||||
|
static std::atomic<ProfilerData*> profilerData { nullptr };
|
||||||
|
|
||||||
static ProfilerData& GetProfilerData()
|
static ProfilerData& GetProfilerData()
|
||||||
{
|
{
|
||||||
// Cannot use magic statics here.
|
auto ptr = profilerData.load( std::memory_order_acquire );
|
||||||
if( !profilerData )
|
if( !ptr )
|
||||||
{
|
{
|
||||||
profilerData = (ProfilerData*)malloc( sizeof( ProfilerData ) );
|
int expected = 0;
|
||||||
new (profilerData) ProfilerData();
|
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 );
|
||||||
|
}
|
||||||
|
profilerDataLock.store( 0, std::memory_order_release );
|
||||||
}
|
}
|
||||||
return *profilerData;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ProfilerThreadData& GetProfilerThreadData()
|
static ProfilerThreadData& GetProfilerThreadData()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user