chore: rename threads on Windows too (#5539)
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user