mirror of
https://github.com/wolfpld/tracy
synced 2025-04-30 12:53:51 +00:00
Use pthread_once() to initialize rpmalloc on linux.
This commit is contained in:
parent
4c28593031
commit
11ba77ced5
@ -87,6 +87,7 @@ extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
|||||||
#if defined __linux__
|
#if defined __linux__
|
||||||
# include <sys/sysinfo.h>
|
# include <sys/sysinfo.h>
|
||||||
# include <sys/utsname.h>
|
# include <sys/utsname.h>
|
||||||
|
# define TRACY_USE_INIT_ONCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined _WIN32 && !defined __CYGWIN__ && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
|
#if !defined _WIN32 && !defined __CYGWIN__ && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
|
||||||
@ -98,6 +99,7 @@ namespace tracy
|
|||||||
|
|
||||||
#ifndef TRACY_DELAYED_INIT
|
#ifndef TRACY_DELAYED_INIT
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
# if defined TRACY_USE_INIT_ONCE
|
||||||
|
# if defined _WIN32 || defined __CYGWIN__
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
BOOL CALLBACK InitOnceCallback(
|
BOOL CALLBACK InitOnceCallback(
|
||||||
@ -111,6 +113,17 @@ namespace
|
|||||||
|
|
||||||
INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT;
|
INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
}
|
}
|
||||||
|
# elif defined __linux__
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void InitOnceCallback()
|
||||||
|
{
|
||||||
|
rpmalloc_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
# endif //if defined TRACY_USE_INIT_ONCE
|
# endif //if defined TRACY_USE_INIT_ONCE
|
||||||
|
|
||||||
struct RPMallocInit
|
struct RPMallocInit
|
||||||
@ -118,9 +131,13 @@ struct RPMallocInit
|
|||||||
RPMallocInit()
|
RPMallocInit()
|
||||||
{
|
{
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
# if defined TRACY_USE_INIT_ONCE
|
||||||
InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr);
|
# if defined _WIN32 || defined __CYGWIN__
|
||||||
//We must call rpmalloc_thread_initialize() explicitly here since the InitOnceCallback might
|
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
||||||
//not be called on this thread if another thread has executed it earlier.
|
# elif defined __linux__
|
||||||
|
pthread_once( &once_control, InitOnceCallback );
|
||||||
|
# endif
|
||||||
|
// We must call rpmalloc_thread_initialize() explicitly here since the InitOnceCallback might
|
||||||
|
// not be called on this thread if another thread has executed it earlier.
|
||||||
rpmalloc_thread_initialize();
|
rpmalloc_thread_initialize();
|
||||||
# else
|
# else
|
||||||
rpmalloc_initialize();
|
rpmalloc_initialize();
|
||||||
@ -133,7 +150,11 @@ struct RPMallocThreadInit
|
|||||||
RPMallocThreadInit()
|
RPMallocThreadInit()
|
||||||
{
|
{
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
# if defined TRACY_USE_INIT_ONCE
|
||||||
InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr);
|
# if defined _WIN32 || defined __CYGWIN__
|
||||||
|
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
||||||
|
# else
|
||||||
|
pthread_once( &once_control, InitOnceCallback );
|
||||||
|
# endif
|
||||||
# endif //if defined TRACY_USE_INIT_ONCE
|
# endif //if defined TRACY_USE_INIT_ONCE
|
||||||
rpmalloc_thread_initialize();
|
rpmalloc_thread_initialize();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user