chore: rename threads on Windows too (#5539)

This commit is contained in:
nerix
2024-08-11 11:23:04 +02:00
committed by GitHub
parent 2b45b2e0a9
commit 1ccdaea8ee
8 changed files with 61 additions and 2 deletions
+41
View File
@@ -0,0 +1,41 @@
#include "util/RenameThread.hpp"
#include "common/QLogging.hpp"
#include <QOperatingSystemVersion>
#ifdef Q_OS_WIN
# include <Windows.h>
namespace chatterino::windows::detail {
void renameThread(HANDLE hThread, const QString &threadName)
{
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Qt 6 requires Windows 10 1809
// Windows 10, version 1607
constexpr QOperatingSystemVersion minVersion{
QOperatingSystemVersion::Windows,
10,
0,
14393,
};
// minVersion is excluded, because it has some additional requirements
if (QOperatingSystemVersion::current() <= minVersion)
{
return;
}
# endif
auto hr = SetThreadDescription(hThread, threadName.toStdWString().c_str());
if (!SUCCEEDED(hr))
{
qCWarning(chatterinoCommon).nospace()
<< "Failed to set thread description, hresult=0x"
<< QString::number(hr, 16);
}
}
} // namespace chatterino::windows::detail
#endif
+8
View File
@@ -9,11 +9,19 @@
namespace chatterino {
#ifdef Q_OS_WIN
namespace windows::detail {
void renameThread(void *hThread, const QString &name);
} // namespace windows::detail
#endif
template <typename T>
void renameThread(T &thread, const QString &threadName)
{
#ifdef Q_OS_LINUX
pthread_setname_np(thread.native_handle(), threadName.toLocal8Bit());
#elif defined(Q_OS_WIN)
windows::detail::renameThread(thread.native_handle(), threadName);
#endif
}