diff options
Diffstat (limited to 'src/zencore/thread.cpp')
| -rw-r--r-- | src/zencore/thread.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index 86609c210..fe81cc786 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -35,6 +35,8 @@ # include <unistd.h> #endif +#include <zencore/trace.h> + #include <thread> ZEN_THIRD_PARTY_INCLUDES_START @@ -94,6 +96,11 @@ const bool bNoZombieChildren = []() { void SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName) { + std::string ThreadNameZ{ThreadName}; + const int ThreadId = GetCurrentThreadId(); + + trace::ThreadRegister(ThreadNameZ.c_str(), /* system id */ ThreadId, /* sort id */ 0); + #if ZEN_PLATFORM_WINDOWS // The SetThreadDescription API works even if no debugger is attached. static auto SetThreadDescriptionFunc = @@ -103,20 +110,17 @@ SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName) { SetThreadDescriptionFunc(::GetCurrentThread(), Utf8ToWide(ThreadName).c_str()); } + // The debugger needs to be around to catch the name in the exception. If // there isn't a debugger, we are just needlessly throwing an exception. - if (!::IsDebuggerPresent()) - return; - - std::string ThreadNameZ{ThreadName}; - SetNameInternal(GetCurrentThreadId(), ThreadNameZ.c_str()); -#else - std::string ThreadNameZ{ThreadName}; -# if ZEN_PLATFORM_MAC + if (::IsDebuggerPresent()) + { + SetNameInternal(ThreadId, ThreadNameZ.c_str()); + } +#elif ZEN_PLATFORM_MAC pthread_setname_np(ThreadNameZ.c_str()); -# else +#else pthread_setname_np(pthread_self(), ThreadNameZ.c_str()); -# endif #endif } // namespace zen |