mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 12:23:53 +00:00
Use generic std::call_once() on other platforms.
This commit is contained in:
parent
5f96c55a3e
commit
e659220602
@ -74,9 +74,6 @@
|
|||||||
#if defined _WIN32 || defined __CYGWIN__
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
# include <lmcons.h>
|
# include <lmcons.h>
|
||||||
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
|
||||||
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
|
||||||
# define TRACY_USE_INIT_ONCE
|
|
||||||
# endif
|
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
@ -87,7 +84,6 @@ 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,50 +94,44 @@ namespace tracy
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifndef TRACY_DELAYED_INIT
|
#ifndef TRACY_DELAYED_INIT
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
|
||||||
# if defined _WIN32 || defined __CYGWIN__
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
BOOL CALLBACK InitOnceCallback(
|
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||||
PINIT_ONCE /*initOnce*/,
|
BOOL CALLBACK InitOnceCallback( PINIT_ONCE /*initOnce*/, PVOID /*Parameter*/, PVOID* /*Context*/)
|
||||||
PVOID /*Parameter*/,
|
|
||||||
PVOID* /*Context*/)
|
|
||||||
{
|
{
|
||||||
rpmalloc_initialize();
|
rpmalloc_initialize();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT;
|
INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
}
|
# elif defined __linux__
|
||||||
# elif defined __linux__
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
void InitOnceCallback()
|
void InitOnceCallback()
|
||||||
{
|
{
|
||||||
rpmalloc_initialize();
|
rpmalloc_initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||||
|
# else
|
||||||
|
void InitOnceCallback()
|
||||||
|
{
|
||||||
|
rpmalloc_initialize();
|
||||||
|
}
|
||||||
|
std::once_flag once_flag;
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
# endif //if defined TRACY_USE_INIT_ONCE
|
|
||||||
|
|
||||||
struct RPMallocInit
|
struct RPMallocInit
|
||||||
{
|
{
|
||||||
RPMallocInit()
|
RPMallocInit()
|
||||||
{
|
{
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||||
# if defined _WIN32 || defined __CYGWIN__
|
|
||||||
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
||||||
# elif defined __linux__
|
# elif defined __linux__
|
||||||
pthread_once( &once_control, InitOnceCallback );
|
pthread_once( &once_control, InitOnceCallback );
|
||||||
# endif
|
# else
|
||||||
|
std::call_once( once_flag, InitOnceCallback );
|
||||||
|
# endif
|
||||||
// We must call rpmalloc_thread_initialize() explicitly here since the InitOnceCallback might
|
// 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.
|
// not be called on this thread if another thread has executed it earlier.
|
||||||
rpmalloc_thread_initialize();
|
rpmalloc_thread_initialize();
|
||||||
# else
|
|
||||||
rpmalloc_initialize();
|
|
||||||
# endif //if defined TRACY_USE_INIT_ONCE
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -149,13 +139,13 @@ struct RPMallocThreadInit
|
|||||||
{
|
{
|
||||||
RPMallocThreadInit()
|
RPMallocThreadInit()
|
||||||
{
|
{
|
||||||
# if defined TRACY_USE_INIT_ONCE
|
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||||
# if defined _WIN32 || defined __CYGWIN__
|
|
||||||
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
|
||||||
# else
|
# elif defined __linux__
|
||||||
pthread_once( &once_control, InitOnceCallback );
|
pthread_once( &once_control, InitOnceCallback );
|
||||||
# endif
|
# else
|
||||||
# endif //if defined TRACY_USE_INIT_ONCE
|
std::call_once( once_flag, InitOnceCallback );
|
||||||
|
# endif
|
||||||
rpmalloc_thread_initialize();
|
rpmalloc_thread_initialize();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user