From cdfe3ee7c80eb62d29d3bd6408903bc460ce2872 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 27 Jan 2024 20:33:54 +0100 Subject: [PATCH] Name some threads --- Utilities/Thread.h | 6 +++--- rpcs3/Emu/NP/np_requests.cpp | 2 ++ rpcs3/Emu/NP/rpcn_client.cpp | 18 ++++++++++++++---- rpcs3/Emu/System.cpp | 2 ++ rpcs3/rpcs3qt/gs_frame.cpp | 2 ++ rpcs3/util/logs.cpp | 2 ++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 8aa3663694..afdbc9d934 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -130,6 +130,9 @@ public: const native_entry entry_point; + // Set name for debugger + static void set_name(std::string); + private: // Thread handle (platform-specific) atomic_t m_thread{0}; @@ -160,9 +163,6 @@ private: // Cleanup after possibly deleting the thread instance static native_entry finalize(u64 _self) noexcept; - // Set name for debugger - static void set_name(std::string); - // Make entry point static native_entry make_trampoline(u64(*entry)(thread_base* _base)); diff --git a/rpcs3/Emu/NP/np_requests.cpp b/rpcs3/Emu/NP/np_requests.cpp index 7a6a811768..4375e2c38c 100644 --- a/rpcs3/Emu/NP/np_requests.cpp +++ b/rpcs3/Emu/NP/np_requests.cpp @@ -764,6 +764,8 @@ namespace np { auto worker_function = [trans_ctx = trans_ctx, req_id, this](std::unique_lock lock) { + thread_base::set_name("NP Trans Worker"); + auto res = trans_ctx->wake_cond.wait_for(lock, std::chrono::microseconds(trans_ctx->timeout)); { std::lock_guard lock_threads(this->mutex_async_transactions); diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 05ec42be8b..41eac9784e 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -135,7 +135,8 @@ namespace rpcn rpcn_client::rpcn_client() : sem_connected(0), sem_authentified(0), sem_reader(0), sem_writer(0), sem_rpcn(0), - thread_rpcn(std::thread(&rpcn_client::rpcn_thread, this)), thread_rpcn_reader(std::thread(&rpcn_client::rpcn_reader_thread, this)), + thread_rpcn(std::thread(&rpcn_client::rpcn_thread, this)), + thread_rpcn_reader(std::thread(&rpcn_client::rpcn_reader_thread, this)), thread_rpcn_writer(std::thread(&rpcn_client::rpcn_writer_thread, this)) { g_cfg_rpcn.load(); @@ -152,9 +153,12 @@ namespace rpcn sem_reader.release(); sem_writer.release(); - thread_rpcn.join(); - thread_rpcn_reader.join(); - thread_rpcn_writer.join(); + if (thread_rpcn.joinable()) + thread_rpcn.join(); + if (thread_rpcn_reader.joinable()) + thread_rpcn_reader.join(); + if (thread_rpcn_writer.joinable()) + thread_rpcn_writer.join(); disconnect(); @@ -196,6 +200,8 @@ namespace rpcn // RPCN thread void rpcn_client::rpcn_reader_thread() { + thread_base::set_name("RPCN Reader"); + while (true) { sem_reader.acquire(); @@ -219,6 +225,8 @@ namespace rpcn void rpcn_client::rpcn_writer_thread() { + thread_base::set_name("RPCN Writer"); + while (true) { sem_writer.acquire(); @@ -241,6 +249,8 @@ namespace rpcn void rpcn_client::rpcn_thread() { + thread_base::set_name("RPCN Client"); + while (true) { sem_rpcn.acquire(); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index e597b7ce7c..3055711cc5 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -2494,6 +2494,8 @@ void Emulator::FinalizeRunRequest() { std::thread([this, info = GetEmulationIdentifier()]() { + thread_base::set_name("Close Home Menu"); + std::this_thread::sleep_for(2s); CallFromMainThread([this]() diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 1476e9a470..0916c7afd2 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -822,6 +822,8 @@ void gs_frame::take_screenshot(std::vector data, u32 sshot_width, u32 sshot_ std::thread( [sshot_width, sshot_height, is_bgra](std::vector sshot_data) { + thread_base::set_name("Screenshot"); + screenshot_log.notice("Taking screenshot (%dx%d)", sshot_width, sshot_height); const std::string& id = Emu.GetTitleID(); diff --git a/rpcs3/util/logs.cpp b/rpcs3/util/logs.cpp index 8c14459871..4e82126832 100644 --- a/rpcs3/util/logs.cpp +++ b/rpcs3/util/logs.cpp @@ -495,6 +495,8 @@ logs::file_writer::file_writer(const std::string& name, u64 max_size) m_writer = std::thread([this]() { + thread_base::set_name("Log Writer"); + thread_ctrl::scoped_priority low_prio(-1); while (true)