From 73cbf2eead54ce0d9cfe12cfe6fa6092bb0280eb Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 13 Aug 2019 16:20:24 +0200 Subject: [PATCH] Use windows thread ids on cygwin. --- client/TracyProfiler.cpp | 1 + common/TracySystem.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index b22d1c92..2c2c13b7 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -15,6 +15,7 @@ #ifdef __CYGWIN__ # include +# include #endif #ifdef _GNU_SOURCE diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 71f720ef..4604f63b 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -6,7 +6,7 @@ # define NOMINMAX # endif #endif -#ifdef _WIN32 +#if defined _WIN32 || defined __CYGWIN__ # include #else # include @@ -34,6 +34,21 @@ # include "TracyAlloc.hpp" #endif +#ifdef __CYGWIN__ +class stub1 // verifyable_object +{ +public: + uint32_t x; + virtual ~stub1(); +}; +class stub2 : public stub1 // pthread +{ +public: + HANDLE hnd; + virtual ~stub2(); +}; +#endif + namespace tracy { @@ -87,7 +102,7 @@ void SetThreadName( std::thread::native_handle_type handle, const char* name ) { } # endif -#elif defined _GNU_SOURCE && !defined __EMSCRIPTEN__ +#elif defined _GNU_SOURCE && !defined __EMSCRIPTEN__ && !defined __CYGWIN__ { const auto sz = strlen( name ); if( sz <= 15 ) @@ -121,6 +136,9 @@ void SetThreadName( std::thread::native_handle_type handle, const char* name ) # endif # elif defined __APPLE__ pthread_threadid_np( handle, &data->id ); +# elif defined __CYGWIN__ + + data->id = GetThreadId( ((stub2*)handle)->hnd ); # else data->id = (uint64_t)handle; # endif @@ -160,7 +178,7 @@ const char* GetThreadName( uint64_t id ) } } # endif -# elif defined __GLIBC__ && !defined __ANDROID__ && !defined __EMSCRIPTEN__ +# elif defined __GLIBC__ && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined __CYGWIN__ if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 ) { return buf;