From 206305fbd223de1d6a2992fbc898f43a8bbc11f7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 25 Sep 2017 21:13:59 +0200 Subject: [PATCH] Merge TracyThread.hpp to TracySystem.cpp. Keeping threading functions inside a source file prevents poisoning by including windows.h. --- client/TracyProfiler.cpp | 1 - client/TracyScoped.hpp | 2 +- client/TracyThread.hpp | 55 ---------------------------------------- common/TracySystem.cpp | 37 +++++++++++++++++++++++++++ common/TracySystem.hpp | 3 +++ 5 files changed, 41 insertions(+), 57 deletions(-) delete mode 100755 client/TracyThread.hpp diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 9b3742c6..07e7be69 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -21,7 +21,6 @@ #include "concurrentqueue.h" #include "TracyScoped.hpp" #include "TracyProfiler.hpp" -#include "TracyThread.hpp" #ifdef _DEBUG # define DISABLE_LZ4 diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index 69774b66..f0259d28 100755 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -3,8 +3,8 @@ #include +#include "../common/TracySystem.hpp" #include "TracyProfiler.hpp" -#include "TracyThread.hpp" namespace tracy { diff --git a/client/TracyThread.hpp b/client/TracyThread.hpp deleted file mode 100755 index bdd5aeff..00000000 --- a/client/TracyThread.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __TRACYTHREAD_HPP__ -#define __TRACYTHREAD_HPP__ - -#include -#include -#include - -#ifdef _MSC_VER -#include -#else -#include -#endif - -namespace tracy -{ - - static inline uint64_t GetThreadHandle() - { -#ifdef _MSC_VER - static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); - return uint64_t( GetCurrentThreadId() ); -#else - static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); - return uint64_t( pthread_self() ); -#endif - } - - static inline const char* GetThreadName( uint64_t id ) - { - static char buf[256]; -#ifdef _MSC_VER -# ifdef NTDDI_WIN10_RS2 - auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, id ); - PWSTR tmp; - GetThreadDescription( hnd, &tmp ); - auto ret = wcstombs( buf, tmp, 256 ); - CloseHandle( hnd ); - if( ret != 0 ) - { - return buf; - } -# endif -#else - if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 ) - { - return buf; - } -#endif - sprintf( buf, "%" PRIu64, id ); - return buf; - } - -} - -#endif diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 35e365b3..3d247720 100755 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -6,12 +6,24 @@ # include #endif +#include #include "TracySystem.hpp" namespace tracy { +uint64_t GetThreadHandle() +{ +#ifdef _MSC_VER + static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); + return uint64_t( GetCurrentThreadId() ); +#else + static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); + return uint64_t( pthread_self() ); +#endif +} + void SetThreadName( std::thread& thread, const char* name ) { #ifdef _WIN32 @@ -62,4 +74,29 @@ void SetThreadName( std::thread& thread, const char* name ) #endif } +const char* GetThreadName( uint64_t id ) +{ + static char buf[256]; +#ifdef _MSC_VER +# ifdef NTDDI_WIN10_RS2 + auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id ); + PWSTR tmp; + GetThreadDescription( hnd, &tmp ); + auto ret = wcstombs( buf, tmp, 256 ); + CloseHandle( hnd ); + if( ret != 0 ) + { + return buf; + } +# endif +#else + if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 ) + { + return buf; + } +#endif + sprintf( buf, "%" PRIu64, id ); + return buf; +} + } diff --git a/common/TracySystem.hpp b/common/TracySystem.hpp index 970d33d4..8097d221 100755 --- a/common/TracySystem.hpp +++ b/common/TracySystem.hpp @@ -1,12 +1,15 @@ #ifndef __TRACYSYSTEM_HPP__ #define __TRACYSYSTEM_HPP__ +#include #include namespace tracy { +uint64_t GetThreadHandle(); void SetThreadName( std::thread& thread, const char* name ); +const char* GetThreadName( uint64_t id ); }