mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Hide rpmalloc init behind thread local boolean.
This commit is contained in:
parent
b0fc0d5dcc
commit
3da84d1579
@ -27,6 +27,7 @@
|
||||
#include "common/TracySocket.cpp"
|
||||
#include "client/tracy_rpmalloc.cpp"
|
||||
#include "client/TracyDxt1.cpp"
|
||||
#include "client/TracyAlloc.cpp"
|
||||
|
||||
#if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
|
||||
# include "libbacktrace/alloc.cpp"
|
||||
|
35
client/TracyAlloc.cpp
Normal file
35
client/TracyAlloc.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#ifdef TRACY_ENABLE
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "../common/TracyAlloc.hpp"
|
||||
#include "../common/TracyYield.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
extern std::atomic<int> RpInitDone;
|
||||
extern std::atomic<int> RpInitLock;
|
||||
|
||||
TRACY_API void InitRpmallocPlumbing()
|
||||
{
|
||||
const auto done = RpInitDone.load( std::memory_order_acquire );
|
||||
if( !done )
|
||||
{
|
||||
int expected = 0;
|
||||
while( !RpInitLock.compare_exchange_weak( expected, 1, std::memory_order_release, std::memory_order_relaxed ) ) { expected = 0; YieldThread(); }
|
||||
const auto done = RpInitDone.load( std::memory_order_acquire );
|
||||
if( !done )
|
||||
{
|
||||
rpmalloc_initialize();
|
||||
RpInitDone.store( 1, std::memory_order_release );
|
||||
}
|
||||
RpInitLock.store( 0, std::memory_order_release );
|
||||
}
|
||||
rpmalloc_thread_initialize();
|
||||
RpThreadInitDone = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -977,6 +977,7 @@ TRACY_API void ShutdownProfiler()
|
||||
# else
|
||||
std::atomic<int> RpInitDone { 0 };
|
||||
std::atomic<int> RpInitLock { 0 };
|
||||
thread_local bool RpThreadInitDone = false;
|
||||
static std::atomic<int> profilerDataLock { 0 };
|
||||
static std::atomic<ProfilerData*> profilerData { nullptr };
|
||||
|
||||
@ -1097,6 +1098,7 @@ thread_local ThreadHandleWrapper init_order(104) s_threadHandle { detail::GetThr
|
||||
static InitTimeWrapper init_order(101) s_initTime { SetupHwTimer() };
|
||||
std::atomic<int> init_order(102) RpInitDone( 0 );
|
||||
std::atomic<int> init_order(102) RpInitLock( 0 );
|
||||
thread_local bool RpThreadInitDone = false;
|
||||
moodycamel::ConcurrentQueue<QueueItem> init_order(103) s_queue( QueuePrealloc );
|
||||
std::atomic<uint32_t> init_order(104) s_lockCounter( 0 );
|
||||
std::atomic<uint8_t> init_order(104) s_gpuCtxCounter( 0 );
|
||||
|
@ -4,9 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
# include <atomic>
|
||||
# include "TracyApi.h"
|
||||
# include "TracyForceInline.hpp"
|
||||
# include "TracyYield.hpp"
|
||||
# include "../client/tracy_rpmalloc.hpp"
|
||||
#endif
|
||||
|
||||
@ -14,30 +13,12 @@ namespace tracy
|
||||
{
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
extern std::atomic<int> RpInitDone;
|
||||
extern std::atomic<int> RpInitLock;
|
||||
|
||||
namespace
|
||||
{
|
||||
static inline void InitRpmallocPlumbing()
|
||||
{
|
||||
int expected = 0;
|
||||
while( !RpInitLock.compare_exchange_weak( expected, 1, std::memory_order_release, std::memory_order_relaxed ) ) { expected = 0; YieldThread(); }
|
||||
const auto done = RpInitDone.load( std::memory_order_acquire );
|
||||
if( !done )
|
||||
{
|
||||
rpmalloc_initialize();
|
||||
RpInitDone.store( 1, std::memory_order_release );
|
||||
}
|
||||
RpInitLock.store( 0, std::memory_order_release );
|
||||
}
|
||||
extern thread_local bool RpThreadInitDone;
|
||||
TRACY_API void InitRpmallocPlumbing();
|
||||
|
||||
static tracy_force_inline void InitRpmalloc()
|
||||
{
|
||||
const auto done = RpInitDone.load( std::memory_order_acquire );
|
||||
if( !done ) InitRpmallocPlumbing();
|
||||
rpmalloc_thread_initialize();
|
||||
}
|
||||
if( !RpThreadInitDone ) InitRpmallocPlumbing();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user