From 809d98162b8c79fb2e9fc3686c387851ef4c9822 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 26 Sep 2017 00:46:46 +0200 Subject: [PATCH] Do the same trick as concurrentqueue.h for GetCurrentThreadId(). --- common/TracySystem.cpp | 11 ----------- common/TracySystem.hpp | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index b45abc6c..a6f02adc 100755 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -13,17 +13,6 @@ 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 diff --git a/common/TracySystem.hpp b/common/TracySystem.hpp index 8097d221..b0848c4a 100755 --- a/common/TracySystem.hpp +++ b/common/TracySystem.hpp @@ -1,13 +1,29 @@ #ifndef __TRACYSYSTEM_HPP__ #define __TRACYSYSTEM_HPP__ +#ifdef _WIN32 +extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void); +#else +# include +#endif + #include #include namespace tracy { -uint64_t GetThreadHandle(); +static inline uint64_t GetThreadHandle() +{ +#ifdef _WIN32 + 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 ); const char* GetThreadName( uint64_t id );