From c3ba0ef4eb7172965f7d018a121d3a34d121a714 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 13 Jul 2018 20:20:37 +0200 Subject: [PATCH] Fix lua zone state init. --- TracyLua.hpp | 37 +++++++++++++++++++------------------ client/TracyProfiler.cpp | 3 +-- client/TracyProfiler.hpp | 8 ++++++++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/TracyLua.hpp b/TracyLua.hpp index 3eca994b..e59fbf79 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -118,8 +118,9 @@ static inline void LuaRemove( char* script ) namespace tracy { -extern thread_local uint32_t s_luaZoneCounter; -extern thread_local bool s_luaZoneActive; +#ifdef TRACY_ON_DEMAND +extern thread_local LuaZoneState s_luaZoneState; +#endif namespace detail { @@ -127,10 +128,10 @@ namespace detail static inline int LuaZoneBegin( lua_State* L ) { #ifdef TRACY_ON_DEMAND - const auto zoneCnt = s_luaZoneCounter++; - if( zoneCnt != 0 && !s_luaZoneActive ) return 0; - s_luaZoneActive = s_profiler.IsConnected(); - if( !s_luaZoneActive ) return 0; + const auto zoneCnt = s_luaZoneState.counter++; + if( zoneCnt != 0 && !s_luaZoneState.active ) return 0; + s_luaZoneState.active = s_profiler.IsConnected(); + if( !s_luaZoneState.active ) return 0; #endif const uint32_t color = Color::DeepSkyBlue3; @@ -181,10 +182,10 @@ static inline int LuaZoneBegin( lua_State* L ) static inline int LuaZoneBeginN( lua_State* L ) { #ifdef TRACY_ON_DEMAND - const auto zoneCnt = s_luaZoneCounter++; - if( zoneCnt != 0 && !s_luaZoneActive ) return 0; - s_luaZoneActive = s_profiler.IsConnected(); - if( !s_luaZoneActive ) return 0; + const auto zoneCnt = s_luaZoneState.counter++; + if( zoneCnt != 0 && !s_luaZoneState.active ) return 0; + s_luaZoneState.active = s_profiler.IsConnected(); + if( !s_luaZoneState.active ) return 0; #endif const uint32_t color = Color::DeepSkyBlue3; @@ -239,12 +240,12 @@ static inline int LuaZoneBeginN( lua_State* L ) static inline int LuaZoneEnd( lua_State* L ) { #ifdef TRACY_ON_DEMAND - assert( s_luaZoneCounter != 0 ); - s_luaZoneCounter--; - if( !s_luaZoneActive ) return 0; + assert( s_luaZoneState.counter != 0 ); + s_luaZoneState.counter--; + if( !s_luaZoneState.active ) return 0; if( !s_profiler.IsConnected() ) { - s_luaZoneActive = false; + s_luaZoneState.active = false; return 0; } #endif @@ -269,10 +270,10 @@ static inline int LuaZoneEnd( lua_State* L ) static inline int LuaZoneText( lua_State* L ) { #ifdef TRACY_ON_DEMAND - if( !s_luaZoneActive ) return 0; + if( !s_luaZoneState.active ) return 0; if( !s_profiler.IsConnected() ) { - s_luaZoneActive = false; + s_luaZoneState.active = false; return 0; } #endif @@ -297,10 +298,10 @@ static inline int LuaZoneText( lua_State* L ) static inline int LuaZoneName( lua_State* L ) { #ifdef TRACY_ON_DEMAND - if( !s_luaZoneActive ) return 0; + if( !s_luaZoneState.active ) return 0; if( !s_profiler.IsConnected() ) { - s_luaZoneActive = false; + s_luaZoneState.active = false; return 0; } #endif diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index cf24876c..1240d218 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -180,8 +180,7 @@ std::atomic init_order(104) s_threadNameData( nullptr ); #endif #ifdef TRACY_ON_DEMAND -thread_local uint32_t init_order(104) s_luaZoneCounter( 0 ); -thread_local bool init_order(104) s_luaZoneActive( false ); +thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; #endif Profiler init_order(105) s_profiler; diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 3623322c..a7332021 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -62,6 +62,14 @@ struct VkCtxWrapper VkCtx* ptr; }; +#ifdef TRACY_ON_DEMAND +struct LuaZoneState +{ + uint32_t counter; + bool active; +}; +#endif + using Magic = tracy::moodycamel::ConcurrentQueueDefaultTraits::index_t; #if __ARM_ARCH >= 6