mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
chore: rename threads on Windows too (#5539)
This commit is contained in:
parent
2b45b2e0a9
commit
1ccdaea8ee
|
@ -61,7 +61,7 @@
|
|||
- Dev: Refactored 7TV/BTTV definitions out of `TwitchIrcServer` into `Application`. (#5532)
|
||||
- Dev: Refactored code that's responsible for deleting old update files. (#5535)
|
||||
- Dev: Cleanly exit on shutdown. (#5537)
|
||||
- Dev: Renamed miniaudio backend thread name. (#5538)
|
||||
- Dev: Renamed threads created by Chatterino on Linux and Windows. (#5538, #5539)
|
||||
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
|
||||
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "BrowserExtension.hpp"
|
||||
|
||||
#include "singletons/NativeMessaging.hpp"
|
||||
#include "util/RenameThread.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
@ -69,6 +70,7 @@ void runLoop()
|
|||
std::this_thread::sleep_for(10s);
|
||||
}
|
||||
});
|
||||
renameThread(thread, "BrowserPingCheck");
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
|
|
@ -511,6 +511,7 @@ set(SOURCE_FILES
|
|||
util/RapidjsonHelpers.hpp
|
||||
util/RatelimitBucket.cpp
|
||||
util/RatelimitBucket.hpp
|
||||
util/RenameThread.cpp
|
||||
util/RenameThread.hpp
|
||||
util/SampleData.cpp
|
||||
util/SampleData.hpp
|
||||
|
|
|
@ -13,6 +13,7 @@ void NetworkManager::init()
|
|||
assert(!NetworkManager::accessManager);
|
||||
|
||||
NetworkManager::workerThread = new QThread;
|
||||
NetworkManager::workerThread->setObjectName("NetworkWorker");
|
||||
NetworkManager::workerThread->start();
|
||||
|
||||
NetworkManager::accessManager = new QNetworkAccessManager;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "util/DebugCount.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
#include "util/RenameThread.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
|
@ -17,6 +18,7 @@
|
|||
#include <exception>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
using websocketpp::lib::bind;
|
||||
|
@ -543,7 +545,10 @@ void PubSub::start()
|
|||
{
|
||||
this->work = std::make_shared<boost::asio::io_service::work>(
|
||||
this->websocketClient.get_io_service());
|
||||
this->thread.reset(new std::thread(std::bind(&PubSub::runThread, this)));
|
||||
this->thread = std::make_unique<std::thread>([this] {
|
||||
runThread();
|
||||
});
|
||||
renameThread(*this->thread, "PubSub");
|
||||
}
|
||||
|
||||
void PubSub::stop()
|
||||
|
|
|
@ -134,6 +134,7 @@ namespace nm::client {
|
|||
NativeMessagingServer::NativeMessagingServer()
|
||||
: thread(*this)
|
||||
{
|
||||
this->thread.setObjectName("NativeMessagingReceiver");
|
||||
}
|
||||
|
||||
NativeMessagingServer::~NativeMessagingServer()
|
||||
|
|
41
src/util/RenameThread.cpp
Normal file
41
src/util/RenameThread.cpp
Normal 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
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue