diff --git a/rpcs3/Input/gui_pad_thread.cpp b/rpcs3/Input/gui_pad_thread.cpp index 3844d7ba9e..aa6e2a9d77 100644 --- a/rpcs3/Input/gui_pad_thread.cpp +++ b/rpcs3/Input/gui_pad_thread.cpp @@ -15,7 +15,6 @@ #endif #include "Emu/Io/PadHandler.h" #include "Emu/system_config.h" -#include "Utilities/Thread.h" #include "rpcs3qt/gui_settings.h" #ifdef __linux__ @@ -43,16 +42,16 @@ atomic_t gui_pad_thread::m_reset = false; gui_pad_thread::gui_pad_thread() { - m_thread = std::make_unique(&gui_pad_thread::run, this); + m_thread = std::make_unique>>("Gui Pad Thread", [this](){ run(); }); } gui_pad_thread::~gui_pad_thread() { - m_terminate = true; - - if (m_thread && m_thread->joinable()) + if (m_thread) { - m_thread->join(); + auto& thread = *m_thread; + thread = thread_state::aborting; + thread(); m_thread.reset(); } @@ -253,13 +252,11 @@ void gui_pad_thread::InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_p void gui_pad_thread::run() { - thread_base::set_name("Gui Pad Thread"); - gui_log.notice("gui_pad_thread: Pad thread started"); m_reset = true; - while (!m_terminate) + while (thread_ctrl::state() != thread_state::aborting) { if (m_reset && m_reset.exchange(false)) { @@ -275,7 +272,7 @@ void gui_pad_thread::run() { m_handler->process(); - if (m_terminate) + if (thread_ctrl::state() == thread_state::aborting) { break; } @@ -283,12 +280,7 @@ void gui_pad_thread::run() process_input(); } - if (m_terminate) - { - break; - } - - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10000); } gui_log.notice("gui_pad_thread: Pad thread stopped"); diff --git a/rpcs3/Input/gui_pad_thread.h b/rpcs3/Input/gui_pad_thread.h index 235d97e8b1..dc04fb456f 100644 --- a/rpcs3/Input/gui_pad_thread.h +++ b/rpcs3/Input/gui_pad_thread.h @@ -6,8 +6,7 @@ #include "Emu/Io/pad_config.h" #include "Emu/Io/pad_config_types.h" #include "Utilities/Timer.h" - -#include +#include "Utilities/Thread.h" class PadHandlerBase; class gui_settings; @@ -62,8 +61,7 @@ protected: std::shared_ptr m_handler; std::shared_ptr m_pad; - std::unique_ptr m_thread; - atomic_t m_terminate = false; + std::unique_ptr>> m_thread; atomic_t m_allow_global_input = false; static atomic_t m_reset;