From 29256df5b175dc7eaa68787f0e1691b061894371 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 7 Sep 2021 21:56:49 +0200 Subject: [PATCH] input: make pad_thread a named_thread --- rpcs3/Emu/system_progress.hpp | 2 +- rpcs3/Input/pad_thread.cpp | 23 +++++++++-------------- rpcs3/Input/pad_thread.h | 13 ++++++------- rpcs3/main_application.cpp | 3 ++- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/system_progress.hpp b/rpcs3/Emu/system_progress.hpp index b9b1422e4a..118447aae5 100644 --- a/rpcs3/Emu/system_progress.hpp +++ b/rpcs3/Emu/system_progress.hpp @@ -37,5 +37,5 @@ struct progress_dialog_server void operator()(); ~progress_dialog_server(); - static auto constexpr thread_name = "Progress Dialog Server"sv; + static constexpr auto thread_name = "Progress Dialog Server"sv; }; diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index c543652e22..7a2c2cd74a 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -14,6 +14,8 @@ #include "Emu/Io/Null/NullPadHandler.h" #include "Emu/Io/PadHandler.h" #include "Emu/Io/pad_config.h" +#include "Emu/System.h" +#include "Utilities/Thread.h" LOG_CHANNEL(input_log, "Input"); @@ -24,7 +26,6 @@ namespace pad std::string g_title_id; atomic_t g_reset{false}; atomic_t g_enabled{true}; - atomic_t g_active{false}; } struct pad_setting @@ -38,19 +39,12 @@ struct pad_setting pad_thread::pad_thread(void *_curthread, void *_curwindow, std::string_view title_id) : curthread(_curthread), curwindow(_curwindow) { pad::g_title_id = title_id; - Init(); - - thread = std::make_shared(&pad_thread::ThreadFunc, this); pad::g_current = this; } pad_thread::~pad_thread() { pad::g_current = nullptr; - pad::g_active = false; - thread->join(); - - handlers.clear(); } void pad_thread::Init() @@ -214,14 +208,15 @@ void pad_thread::SetIntercepted(bool intercepted) } } -void pad_thread::ThreadFunc() +void pad_thread::operator()() { - pad::g_active = true; - while (pad::g_active) + pad::g_reset = true; + + while (thread_ctrl::state() != thread_state::aborting) { - if (!pad::g_enabled) + if (!pad::g_enabled || Emu.IsPaused()) { - std::this_thread::sleep_for(1ms); + thread_ctrl::wait_for(10000); continue; } @@ -276,7 +271,7 @@ void pad_thread::ThreadFunc() } } - std::this_thread::sleep_for(1ms); + thread_ctrl::wait_for(1000); } } diff --git a/rpcs3/Input/pad_thread.h b/rpcs3/Input/pad_thread.h index e5d9a0d899..9d08e61799 100644 --- a/rpcs3/Input/pad_thread.h +++ b/rpcs3/Input/pad_thread.h @@ -8,7 +8,6 @@ #include "Utilities/mutex.h" #include -#include #include #include #include @@ -23,10 +22,11 @@ public: pad_thread& operator=(const pad_thread&) = delete; ~pad_thread(); + void operator()(); + PadInfo& GetInfo() { return m_info; } auto& GetPads() { return m_pads; } void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor); - void Init(); void SetIntercepted(bool intercepted); s32 AddLddPad(); @@ -35,9 +35,11 @@ public: static std::shared_ptr GetHandler(pad_handler type); static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr& handler); + static auto constexpr thread_name = "Pad Thread"sv; + protected: + void Init(); void InitLddPad(u32 handle); - void ThreadFunc(); // List of all handlers std::map> handlers; @@ -49,8 +51,6 @@ protected: PadInfo m_info{ 0, 0, false }; std::array, CELL_PAD_MAX_PORT_NUM> m_pads; - std::shared_ptr thread; - u32 num_ldd_pad = 0; }; @@ -61,7 +61,6 @@ namespace pad extern std::string g_title_id; extern atomic_t g_enabled; extern atomic_t g_reset; - extern atomic_t g_active; static inline class pad_thread* get_current_handler(bool relaxed = false) { @@ -81,7 +80,7 @@ namespace pad static inline void reset(std::string_view title_id) { g_title_id = title_id; - g_reset = g_active.load(); + g_reset = true; } static inline void SetIntercepted(bool intercepted) diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index f491709a7f..12c78b0666 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -4,6 +4,7 @@ #include "util/logs.hpp" #include "util/sysinfo.hpp" +#include "Utilities/Thread.h" #include "Input/pad_thread.h" #include "Emu/System.h" #include "Emu/system_config.h" @@ -99,7 +100,7 @@ EmuCallbacks main_application::CreateCallbacks() callbacks.init_pad_handler = [this](std::string_view title_id) { - g_fxo->init(get_thread(), m_game_window, title_id); + g_fxo->init>(get_thread(), m_game_window, title_id); }; callbacks.get_audio = []() -> std::shared_ptr