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

View File

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

View File

@ -102,7 +102,7 @@ private:
int samples_avail;
#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_should_couninit = false;
#endif

View File

@ -120,7 +120,7 @@ private:
IPCReply HandleICMPPingRequest(const IOCtlVRequest& request);
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::queue<AsyncReply> m_async_replies;
};

View File

@ -54,7 +54,7 @@ private:
NWC24::NWC24Config config;
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::queue<AsyncReply> m_async_replies;
// TODO: Maybe move away from Common::HttpRequest?

View File

@ -85,7 +85,7 @@ struct CompressAndDumpState_args
static std::mutex s_save_thread_mutex;
// 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
// 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
QMap<QString, QSet<QString>> m_tracked_files;
QVector<QString> m_tracked_paths;
Common::WorkQueueThread<Command> m_load_thread;
Common::WorkQueueThread<Command> m_load_thread{"GameList Tracker"};
UICommon::GameFileCache m_cache;
Common::Event m_cache_loaded_event;
Common::Event m_initial_games_emitted_event;