Use named_thread in gui_pad_thread

This commit is contained in:
Megamouse 2025-03-11 20:31:25 +01:00
parent 3737cc37f6
commit 4c788abad1
2 changed files with 10 additions and 20 deletions

View file

@ -15,7 +15,6 @@
#endif #endif
#include "Emu/Io/PadHandler.h" #include "Emu/Io/PadHandler.h"
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include "Utilities/Thread.h"
#include "rpcs3qt/gui_settings.h" #include "rpcs3qt/gui_settings.h"
#ifdef __linux__ #ifdef __linux__
@ -43,16 +42,16 @@ atomic_t<bool> gui_pad_thread::m_reset = false;
gui_pad_thread::gui_pad_thread() gui_pad_thread::gui_pad_thread()
{ {
m_thread = std::make_unique<std::thread>(&gui_pad_thread::run, this); m_thread = std::make_unique<named_thread<std::function<void()>>>("Gui Pad Thread", [this](){ run(); });
} }
gui_pad_thread::~gui_pad_thread() gui_pad_thread::~gui_pad_thread()
{ {
m_terminate = true; if (m_thread)
if (m_thread && m_thread->joinable())
{ {
m_thread->join(); auto& thread = *m_thread;
thread = thread_state::aborting;
thread();
m_thread.reset(); 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() void gui_pad_thread::run()
{ {
thread_base::set_name("Gui Pad Thread");
gui_log.notice("gui_pad_thread: Pad thread started"); gui_log.notice("gui_pad_thread: Pad thread started");
m_reset = true; m_reset = true;
while (!m_terminate) while (thread_ctrl::state() != thread_state::aborting)
{ {
if (m_reset && m_reset.exchange(false)) if (m_reset && m_reset.exchange(false))
{ {
@ -275,7 +272,7 @@ void gui_pad_thread::run()
{ {
m_handler->process(); m_handler->process();
if (m_terminate) if (thread_ctrl::state() == thread_state::aborting)
{ {
break; break;
} }
@ -283,12 +280,7 @@ void gui_pad_thread::run()
process_input(); process_input();
} }
if (m_terminate) thread_ctrl::wait_for(10000);
{
break;
}
std::this_thread::sleep_for(10ms);
} }
gui_log.notice("gui_pad_thread: Pad thread stopped"); gui_log.notice("gui_pad_thread: Pad thread stopped");

View file

@ -6,8 +6,7 @@
#include "Emu/Io/pad_config.h" #include "Emu/Io/pad_config.h"
#include "Emu/Io/pad_config_types.h" #include "Emu/Io/pad_config_types.h"
#include "Utilities/Timer.h" #include "Utilities/Timer.h"
#include "Utilities/Thread.h"
#include <thread>
class PadHandlerBase; class PadHandlerBase;
class gui_settings; class gui_settings;
@ -62,8 +61,7 @@ protected:
std::shared_ptr<PadHandlerBase> m_handler; std::shared_ptr<PadHandlerBase> m_handler;
std::shared_ptr<Pad> m_pad; std::shared_ptr<Pad> m_pad;
std::unique_ptr<std::thread> m_thread; std::unique_ptr<named_thread<std::function<void()>>> m_thread;
atomic_t<bool> m_terminate = false;
atomic_t<bool> m_allow_global_input = false; atomic_t<bool> m_allow_global_input = false;
static atomic_t<bool> m_reset; static atomic_t<bool> m_reset;