Use generic std::call_once() on other platforms.

This commit is contained in:
Bartosz Taudul 2019-07-25 23:30:47 +02:00
parent 5f96c55a3e
commit e659220602

View File

@ -74,9 +74,6 @@
#if defined _WIN32 || defined __CYGWIN__
# include <lmcons.h>
extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
# define TRACY_USE_INIT_ONCE
# endif
#else
# include <unistd.h>
# include <limits.h>
@ -87,7 +84,6 @@ extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW );
#if defined __linux__
# include <sys/sysinfo.h>
# include <sys/utsname.h>
# define TRACY_USE_INIT_ONCE
#endif
#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
# if defined TRACY_USE_INIT_ONCE
# if defined _WIN32 || defined __CYGWIN__
namespace
{
BOOL CALLBACK InitOnceCallback(
PINIT_ONCE /*initOnce*/,
PVOID /*Parameter*/,
PVOID* /*Context*/)
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
BOOL CALLBACK InitOnceCallback( PINIT_ONCE /*initOnce*/, PVOID /*Parameter*/, PVOID* /*Context*/)
{
rpmalloc_initialize();
return TRUE;
}
INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT;
}
# elif defined __linux__
namespace
{
# elif defined __linux__
void InitOnceCallback()
{
rpmalloc_initialize();
}
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
{
RPMallocInit()
{
# if defined TRACY_USE_INIT_ONCE
# if defined _WIN32 || defined __CYGWIN__
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
# elif defined __linux__
# elif defined __linux__
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
// not be called on this thread if another thread has executed it earlier.
rpmalloc_thread_initialize();
# else
rpmalloc_initialize();
# endif //if defined TRACY_USE_INIT_ONCE
}
};
@ -149,13 +139,13 @@ struct RPMallocThreadInit
{
RPMallocThreadInit()
{
# if defined TRACY_USE_INIT_ONCE
# if defined _WIN32 || defined __CYGWIN__
# if ( defined _WIN32 || defined __CYGWIN__ ) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
InitOnceExecuteOnce( &InitOnce, InitOnceCallback, nullptr, nullptr );
# else
# elif defined __linux__
pthread_once( &once_control, InitOnceCallback );
# endif
# endif //if defined TRACY_USE_INIT_ONCE
# else
std::call_once( once_flag, InitOnceCallback );
# endif
rpmalloc_thread_initialize();
}
};