From 47f73355415c3fff66a6db131bed1c9d1bfeb80f Mon Sep 17 00:00:00 2001 From: Ziemas Date: Sat, 23 Jul 2022 16:27:42 +0200 Subject: [PATCH] Set thread names of system threads (#1697) Set thread names --- game/system/SystemThread.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/game/system/SystemThread.cpp b/game/system/SystemThread.cpp index d96df8f142..9af0d955aa 100644 --- a/game/system/SystemThread.cpp +++ b/game/system/SystemThread.cpp @@ -1,6 +1,19 @@ #include "SystemThread.h" #include "common/log/log.h" +#include "common/util/unicode_util.h" + +#ifdef __linux +#include +#else +// Include order matters... +// clang-format off +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN +#include +#include +// clang-format on +#endif ////////////////////// // Thread Manager // @@ -82,6 +95,13 @@ bool SystemThreadManager::all_threads_exiting() { void* bootstrap_thread_func(void* x) { SystemThread* thd = (SystemThread*)x; SystemThreadInterface iface(thd); + +#ifdef __linux__ + pthread_setname_np(pthread_self(), thd->name.c_str()); +#else + SetThreadDescription(GetCurrentThread(), (LPCWSTR)utf8_string_to_wide_string(thd->name).c_str()); +#endif + thd->function(iface); lg::debug("[SYSTEM] Thread {} is returning", thd->name.c_str()); return nullptr;