LogitechG27: use named_thread instead of std::thread

This commit is contained in:
Megamouse 2025-05-13 21:45:58 +02:00 committed by Elad
parent bc18b3592c
commit 8d9ba4329d
2 changed files with 12 additions and 11 deletions

View file

@ -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<named_thread<std::function<void()>>>("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<u32, std::vector<SDL_Joystick*>>& 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
{

View file

@ -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 <map>
#include <vector>
#include <thread>
enum class logitech_g27_ffb_state
{
@ -122,6 +122,5 @@ private:
bool m_enabled = false;
std::thread m_house_keeping_thread;
atomic_t<bool> m_stop_thread { false };
std::unique_ptr<named_thread<std::function<void()>>> m_house_keeping_thread;
};