WorkQueueThread: Implement thread name

Otherwise we will end up with a dozen threads named "WorkQueueThread"
This commit is contained in:
Scott Mansell
2023-02-04 11:31:49 +13:00
parent 94a0c50bf8
commit acdb0c5be1
7 changed files with 14 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include <functional> #include <functional>
#include <queue> #include <queue>
#include <string>
#include <thread> #include <thread>
#include "Common/Event.h" #include "Common/Event.h"
@ -19,8 +20,11 @@ template <typename T>
class WorkQueueThread class WorkQueueThread
{ {
public: public:
WorkQueueThread() = default; WorkQueueThread(std::string name) : m_thread_name(name){};
WorkQueueThread(std::function<void(T)> function) { Reset(std::move(function)); } WorkQueueThread(std::function<void(T)> function, std::string name) : m_thread_name(name)
{
Reset(std::move(function));
}
~WorkQueueThread() { Shutdown(); } ~WorkQueueThread() { Shutdown(); }
void Reset(std::function<void(T)> function) void Reset(std::function<void(T)> function)
{ {
@ -139,7 +143,7 @@ public:
private: private:
void ThreadLoop() void ThreadLoop()
{ {
Common::SetCurrentThreadName("WorkQueueThread"); Common::SetCurrentThreadName(m_thread_name.c_str());
while (true) while (true)
{ {
@ -166,6 +170,7 @@ private:
} }
std::function<void(T)> m_function; std::function<void(T)> m_function;
std::string m_thread_name;
std::thread m_thread; std::thread m_thread;
std::mutex m_lock; std::mutex m_lock;
std::queue<T> m_items; std::queue<T> m_items;

View File

@ -200,7 +200,7 @@ CEXIMic::CEXIMic(int index)
: slot(index) : slot(index)
#ifdef _WIN32 #ifdef _WIN32
, ,
m_work_queue([](const std::function<void()>& func) { func(); }) m_work_queue([](const std::function<void()>& func) { func(); }, "Mic Worker")
#endif #endif
{ {
m_position = 0; m_position = 0;

View File

@ -102,7 +102,7 @@ private:
int samples_avail; int samples_avail;
#ifdef _WIN32 #ifdef _WIN32
Common::WorkQueueThread<std::function<void()>> m_work_queue; Common::WorkQueueThread<std::function<void()>> m_work_queue{"Mic Worker"};
bool m_coinit_success = false; bool m_coinit_success = false;
bool m_should_couninit = false; bool m_should_couninit = false;
#endif #endif

View File

@ -120,7 +120,7 @@ private:
IPCReply HandleICMPPingRequest(const IOCtlVRequest& request); IPCReply HandleICMPPingRequest(const IOCtlVRequest& request);
Common::SocketContext m_socket_context; Common::SocketContext m_socket_context;
Common::WorkQueueThread<AsyncTask> m_work_queue; Common::WorkQueueThread<AsyncTask> m_work_queue{"Network Worker"};
std::mutex m_async_reply_lock; std::mutex m_async_reply_lock;
std::queue<AsyncReply> m_async_replies; std::queue<AsyncReply> m_async_replies;
}; };

View File

@ -54,7 +54,7 @@ private:
NWC24::NWC24Config config; NWC24::NWC24Config config;
NWC24::NWC24Dl m_dl_list; NWC24::NWC24Dl m_dl_list;
Common::WorkQueueThread<AsyncTask> m_work_queue; Common::WorkQueueThread<AsyncTask> m_work_queue{"WiiConnect24 Worker"};
std::mutex m_async_reply_lock; std::mutex m_async_reply_lock;
std::queue<AsyncReply> m_async_replies; std::queue<AsyncReply> m_async_replies;
// TODO: Maybe move away from Common::HttpRequest? // TODO: Maybe move away from Common::HttpRequest?

View File

@ -85,7 +85,7 @@ struct CompressAndDumpState_args
static std::mutex s_save_thread_mutex; static std::mutex s_save_thread_mutex;
// Queue for compressing and writing savestates to disk. // Queue for compressing and writing savestates to disk.
static Common::WorkQueueThread<CompressAndDumpState_args> s_save_thread; static Common::WorkQueueThread<CompressAndDumpState_args> s_save_thread("Savestate Worker");
// Keeps track of savestate writes that are currently happening, so we don't load a state while // Keeps track of savestate writes that are currently happening, so we don't load a state while
// another one is still saving. This is particularly important so if you save to a slot and then // another one is still saving. This is particularly important so if you save to a slot and then

View File

@ -87,7 +87,7 @@ private:
// game path -> directories that track it // game path -> directories that track it
QMap<QString, QSet<QString>> m_tracked_files; QMap<QString, QSet<QString>> m_tracked_files;
QVector<QString> m_tracked_paths; QVector<QString> m_tracked_paths;
Common::WorkQueueThread<Command> m_load_thread; Common::WorkQueueThread<Command> m_load_thread{"GameList Tracker"};
UICommon::GameFileCache m_cache; UICommon::GameFileCache m_cache;
Common::Event m_cache_loaded_event; Common::Event m_cache_loaded_event;
Common::Event m_initial_games_emitted_event; Common::Event m_initial_games_emitted_event;