From 7c4fcc30a369763b9fd5f04964d275c707fb17c2 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 4 Feb 2023 15:56:27 +1300 Subject: [PATCH] WorkQueueThread: provide name and function at same time --- Source/Core/AudioCommon/CubebStream.cpp | 2 +- Source/Core/Common/WorkQueueThread.h | 9 +++++---- Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp | 2 +- Source/Core/Core/HW/EXI/EXI_DeviceMic.h | 2 +- Source/Core/Core/IOS/Network/IP/Top.cpp | 2 +- Source/Core/Core/IOS/Network/IP/Top.h | 2 +- Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp | 2 +- Source/Core/Core/IOS/Network/KD/NetKDRequest.h | 2 +- Source/Core/Core/State.cpp | 4 ++-- Source/Core/DolphinQt/GameList/GameTracker.cpp | 2 +- Source/Core/DolphinQt/GameList/GameTracker.h | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/Core/AudioCommon/CubebStream.cpp b/Source/Core/AudioCommon/CubebStream.cpp index f4566cb57e..92ab886580 100644 --- a/Source/Core/AudioCommon/CubebStream.cpp +++ b/Source/Core/AudioCommon/CubebStream.cpp @@ -39,7 +39,7 @@ void CubebStream::StateCallback(cubeb_stream* stream, void* user_data, cubeb_sta CubebStream::CubebStream() #ifdef _WIN32 - : m_work_queue([](const std::function& func) { func(); }) + : m_work_queue("Cubeb Worker", [](const std::function& func) { func(); }) { Common::Event sync_event; m_work_queue.EmplaceItem([this, &sync_event] { diff --git a/Source/Core/Common/WorkQueueThread.h b/Source/Core/Common/WorkQueueThread.h index f7c70edee8..74074a326a 100644 --- a/Source/Core/Common/WorkQueueThread.h +++ b/Source/Core/Common/WorkQueueThread.h @@ -20,19 +20,20 @@ template class WorkQueueThread { public: - WorkQueueThread(std::string name) : m_thread_name(name){}; - WorkQueueThread(std::function function, std::string name) : m_thread_name(name) + WorkQueueThread() = default; + WorkQueueThread(const std::string name, std::function function) { - Reset(std::move(function)); + Reset(std::move(name), std::move(function)); } ~WorkQueueThread() { Shutdown(); } // Shuts the current work thread down (if any) and starts a new thread with the given function // Note: Some consumers of this API push items to the queue before starting the thread. - void Reset(std::function function) + void Reset(const std::string& name, std::function function) { Shutdown(); std::lock_guard lg(m_lock); + m_thread_name = std::move(name); m_shutdown = false; m_function = std::move(function); m_thread = std::thread(&WorkQueueThread::ThreadLoop, this); diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp index 7aac4177b5..e88cd6162c 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp @@ -200,7 +200,7 @@ CEXIMic::CEXIMic(int index) : slot(index) #ifdef _WIN32 , - m_work_queue([](const std::function& func) { func(); }, "Mic Worker") + m_work_queue("Mic Worker", [](const std::function& func) { func(); }) #endif { m_position = 0; diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMic.h b/Source/Core/Core/HW/EXI/EXI_DeviceMic.h index 937665525b..a831ef33e5 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMic.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMic.h @@ -102,7 +102,7 @@ private: int samples_avail; #ifdef _WIN32 - Common::WorkQueueThread> m_work_queue{"Mic Worker"}; + Common::WorkQueueThread> m_work_queue; bool m_coinit_success = false; bool m_should_couninit = false; #endif diff --git a/Source/Core/Core/IOS/Network/IP/Top.cpp b/Source/Core/Core/IOS/Network/IP/Top.cpp index ac512be37c..27487918d0 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.cpp +++ b/Source/Core/Core/IOS/Network/IP/Top.cpp @@ -65,7 +65,7 @@ enum SOResultCode : s32 NetIPTopDevice::NetIPTopDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name) { - m_work_queue.Reset([this](AsyncTask task) { + m_work_queue.Reset("Network Worker", [this](AsyncTask task) { const IPCReply reply = task.handler(); { std::lock_guard lg(m_async_reply_lock); diff --git a/Source/Core/Core/IOS/Network/IP/Top.h b/Source/Core/Core/IOS/Network/IP/Top.h index 1e5f86cb29..cc41180860 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.h +++ b/Source/Core/Core/IOS/Network/IP/Top.h @@ -120,7 +120,7 @@ private: IPCReply HandleICMPPingRequest(const IOCtlVRequest& request); Common::SocketContext m_socket_context; - Common::WorkQueueThread m_work_queue{"Network Worker"}; + Common::WorkQueueThread m_work_queue; std::mutex m_async_reply_lock; std::queue m_async_replies; }; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index 1e8063a60d..8c5f80b6d4 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -150,7 +150,7 @@ s32 NWC24MakeUserID(u64* nwc24_id, u32 hollywood_id, u16 id_ctr, HardwareModel h NetKDRequestDevice::NetKDRequestDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name), config{ios.GetFS()}, m_dl_list{ios.GetFS()} { - m_work_queue.Reset([this](AsyncTask task) { + m_work_queue.Reset("WiiConnect24 Worker", [this](AsyncTask task) { const IPCReply reply = task.handler(); { std::lock_guard lg(m_async_reply_lock); diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h index 8d2cb9153c..aae52a11f5 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.h +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.h @@ -54,7 +54,7 @@ private: NWC24::NWC24Config config; NWC24::NWC24Dl m_dl_list; - Common::WorkQueueThread m_work_queue{"WiiConnect24 Worker"}; + Common::WorkQueueThread m_work_queue; std::mutex m_async_reply_lock; std::queue m_async_replies; // TODO: Maybe move away from Common::HttpRequest? diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index f045afadb5..fe1a270b2c 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -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 s_save_thread("Savestate Worker"); +static Common::WorkQueueThread s_save_thread; // 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 @@ -724,7 +724,7 @@ void Init() if (lzo_init() != LZO_E_OK) PanicAlertFmtT("Internal LZO Error - lzo_init() failed"); - s_save_thread.Reset([](CompressAndDumpState_args args) { + s_save_thread.Reset("Savestate Worker", [](CompressAndDumpState_args args) { CompressAndDumpState(args); { diff --git a/Source/Core/DolphinQt/GameList/GameTracker.cpp b/Source/Core/DolphinQt/GameList/GameTracker.cpp index 6298bbdca1..9428729997 100644 --- a/Source/Core/DolphinQt/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt/GameList/GameTracker.cpp @@ -55,7 +55,7 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent) m_load_thread.EmplaceItem(Command{CommandType::UpdateMetadata, {}}); }); - m_load_thread.Reset([this](Command command) { + m_load_thread.Reset("GameList Tracker", [this](Command command) { switch (command.type) { case CommandType::LoadCache: diff --git a/Source/Core/DolphinQt/GameList/GameTracker.h b/Source/Core/DolphinQt/GameList/GameTracker.h index 1cfd02e62a..97ec5bb268 100644 --- a/Source/Core/DolphinQt/GameList/GameTracker.h +++ b/Source/Core/DolphinQt/GameList/GameTracker.h @@ -87,7 +87,7 @@ private: // game path -> directories that track it QMap> m_tracked_files; QVector m_tracked_paths; - Common::WorkQueueThread m_load_thread{"GameList Tracker"}; + Common::WorkQueueThread m_load_thread; UICommon::GameFileCache m_cache; Common::Event m_cache_loaded_event; Common::Event m_initial_games_emitted_event;