From 8d9ba4329d47ab8745566d8a6074342fa8e928af Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 13 May 2025 21:45:58 +0200 Subject: [PATCH] LogitechG27: use named_thread instead of std::thread --- rpcs3/Emu/Io/LogitechG27.cpp | 18 ++++++++++-------- rpcs3/Emu/Io/LogitechG27.h | 5 ++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/rpcs3/Emu/Io/LogitechG27.cpp b/rpcs3/Emu/Io/LogitechG27.cpp index b2311719d8..8c1e7cc289 100644 --- a/rpcs3/Emu/Io/LogitechG27.cpp +++ b/rpcs3/Emu/Io/LogitechG27.cpp @@ -58,12 +58,12 @@ usb_device_logitech_g27::usb_device_logitech_g27(u32 controller_index, const std if (!m_enabled) return; - m_house_keeping_thread = std::thread([this]() + m_house_keeping_thread = std::make_unique>>("Logitech G27", [this]() { - while (!m_stop_thread) + while (thread_ctrl::state() != thread_state::aborting) { sdl_refresh(); - std::this_thread::sleep_for(std::chrono::seconds(5)); + thread_ctrl::wait_for(5'000'000); } }); } @@ -88,12 +88,14 @@ static void clear_sdl_joysticks(std::map>& joyst usb_device_logitech_g27::~usb_device_logitech_g27() { - // stop the house keeping thread - m_stop_thread = true; - // wait for the house keeping thread to finish - if (m_house_keeping_thread.joinable()) - m_house_keeping_thread.join(); + if (m_house_keeping_thread) + { + auto& thread = *m_house_keeping_thread; + thread = thread_state::aborting; + thread(); + m_house_keeping_thread.reset(); + } // Close sdl handles { diff --git a/rpcs3/Emu/Io/LogitechG27.h b/rpcs3/Emu/Io/LogitechG27.h index 5a8406486a..242856ef67 100644 --- a/rpcs3/Emu/Io/LogitechG27.h +++ b/rpcs3/Emu/Io/LogitechG27.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Io/usb_device.h" +#include "Utilities/Thread.h" #include "LogitechG27Config.h" #ifndef _MSC_VER @@ -14,7 +15,6 @@ #include #include -#include enum class logitech_g27_ffb_state { @@ -122,6 +122,5 @@ private: bool m_enabled = false; - std::thread m_house_keeping_thread; - atomic_t m_stop_thread { false }; + std::unique_ptr>> m_house_keeping_thread; };