From 27447902ef1d65070ce24d22b2bb33cf79dc161b Mon Sep 17 00:00:00 2001 From: Sherief Farouk Date: Sat, 27 Oct 2018 18:13:59 -0700 Subject: [PATCH 1/3] Fix for using Tracy with multithreaded NT loader in Windows 10 RS5 (Issue #26). --- client/TracyProfiler.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index e4a03dd6..07973756 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -56,6 +56,7 @@ #if defined _MSC_VER || defined __CYGWIN__ # include extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); +# define TRACY_USE_INITONCE (1) #else # include # include @@ -73,12 +74,40 @@ namespace tracy struct RPMallocInit { - RPMallocInit() { rpmalloc_initialize(); } + RPMallocInit() + { + #if defined TRACY_USE_INITONCE + rpmalloc_thread_initialize(); + #else + rpmalloc_initialize(); + #endif //if defined TRACY_USE_INITONCE + } }; +#if defined TRACY_USE_INITONCE +namespace +{ + BOOL CALLBACK InitOnceCallback( + PINIT_ONCE initOnce, + PVOID Parameter, + PVOID *Context) + { + rpmalloc_initialize(); + return TRUE; + } +} +#endif //if defined TRACY_USE_INITONCE + struct RPMallocThreadInit { - RPMallocThreadInit() { rpmalloc_thread_initialize(); } + RPMallocThreadInit() + { + #if defined TRACY_USE_INITONCE + static INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT; + InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr); + #endif //if defined TRACY_USE_INITONCE + rpmalloc_thread_initialize(); + } }; struct InitTimeWrapper From 5110d55f1748ac1b7da952667e2870d300c10cfe Mon Sep 17 00:00:00 2001 From: Sherief Farouk Date: Sun, 28 Oct 2018 18:55:55 -0700 Subject: [PATCH 2/3] Fix for using Tracy with multithreaded NT loader in Windows 10 RS5 (Issue #26) [Take 2]. --- client/TracyProfiler.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 07973756..71facb47 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -56,7 +56,7 @@ #if defined _MSC_VER || defined __CYGWIN__ # include extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); -# define TRACY_USE_INITONCE (1) +# define TRACY_USE_INITONCE #else # include # include @@ -72,18 +72,6 @@ extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); namespace tracy { -struct RPMallocInit -{ - RPMallocInit() - { - #if defined TRACY_USE_INITONCE - rpmalloc_thread_initialize(); - #else - rpmalloc_initialize(); - #endif //if defined TRACY_USE_INITONCE - } -}; - #if defined TRACY_USE_INITONCE namespace { @@ -95,17 +83,35 @@ namespace rpmalloc_initialize(); return TRUE; } + + INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT; } #endif //if defined TRACY_USE_INITONCE +struct RPMallocInit +{ + RPMallocInit() + { +#if defined TRACY_USE_INITONCE + InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr); + //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_INITONCE + } +}; + + + struct RPMallocThreadInit { RPMallocThreadInit() { - #if defined TRACY_USE_INITONCE - static INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT; +#if defined TRACY_USE_INITONCE InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr); - #endif //if defined TRACY_USE_INITONCE +#endif //if defined TRACY_USE_INITONCE rpmalloc_thread_initialize(); } }; From 591f04ad0f51931e23ad663348f785b96a212c58 Mon Sep 17 00:00:00 2001 From: Sherief Farouk Date: Sun, 28 Oct 2018 22:41:08 -0700 Subject: [PATCH 3/3] Renamed preprocessor #define for consistency. --- client/TracyProfiler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 71facb47..5740d4e0 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -56,7 +56,7 @@ #if defined _MSC_VER || defined __CYGWIN__ # include extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); -# define TRACY_USE_INITONCE +# define TRACY_USE_INIT_ONCE #else # include # include @@ -72,7 +72,7 @@ extern "C" typedef LONG (WINAPI *t_RtlGetVersion)( PRTL_OSVERSIONINFOW ); namespace tracy { -#if defined TRACY_USE_INITONCE +#if defined TRACY_USE_INIT_ONCE namespace { BOOL CALLBACK InitOnceCallback( @@ -86,20 +86,20 @@ namespace INIT_ONCE InitOnce = INIT_ONCE_STATIC_INIT; } -#endif //if defined TRACY_USE_INITONCE +#endif //if defined TRACY_USE_INIT_ONCE struct RPMallocInit { RPMallocInit() { -#if defined TRACY_USE_INITONCE +#if defined TRACY_USE_INIT_ONCE InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr); //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_INITONCE +#endif //if defined TRACY_USE_INIT_ONCE } }; @@ -109,9 +109,9 @@ struct RPMallocThreadInit { RPMallocThreadInit() { -#if defined TRACY_USE_INITONCE +#if defined TRACY_USE_INIT_ONCE InitOnceExecuteOnce(&InitOnce, InitOnceCallback, nullptr, nullptr); -#endif //if defined TRACY_USE_INITONCE +#endif //if defined TRACY_USE_INIT_ONCE rpmalloc_thread_initialize(); } };