1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Hide rpmalloc init behind thread local boolean.

This commit is contained in:
Bartosz Taudul
2021-05-31 22:38:22 +02:00
parent b0fc0d5dcc
commit 3da84d1579
4 changed files with 42 additions and 23 deletions
+4 -23
View File
@@ -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