input_common: Make use of StoppableTimedWait

This commit is contained in:
Morph 2023-01-25 16:03:54 -05:00
parent 9b0563fa87
commit c55147b24a
2 changed files with 6 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "common/polyfill_thread.h"
#include "common/settings_input.h" #include "common/settings_input.h"
#include "common/thread.h" #include "common/thread.h"
#include "input_common/drivers/gc_adapter.h" #include "input_common/drivers/gc_adapter.h"
@ -217,8 +218,7 @@ void GCAdapter::AdapterScanThread(std::stop_token stop_token) {
Common::SetCurrentThreadName("ScanGCAdapter"); Common::SetCurrentThreadName("ScanGCAdapter");
usb_adapter_handle = nullptr; usb_adapter_handle = nullptr;
pads = {}; pads = {};
while (!stop_token.stop_requested() && !Setup()) { while (!Setup() && Common::StoppableTimedWait(stop_token, std::chrono::seconds{2})) {
std::this_thread::sleep_for(std::chrono::seconds(2));
} }
} }

View File

@ -5,6 +5,7 @@
#include "common/param_package.h" #include "common/param_package.h"
#include "common/polyfill_ranges.h" #include "common/polyfill_ranges.h"
#include "common/polyfill_thread.h"
#include "common/settings.h" #include "common/settings.h"
#include "common/thread.h" #include "common/thread.h"
#include "input_common/drivers/joycon.h" #include "input_common/drivers/joycon.h"
@ -67,7 +68,8 @@ void Joycons::Setup() {
void Joycons::ScanThread(std::stop_token stop_token) { void Joycons::ScanThread(std::stop_token stop_token) {
constexpr u16 nintendo_vendor_id = 0x057e; constexpr u16 nintendo_vendor_id = 0x057e;
Common::SetCurrentThreadName("JoyconScanThread"); Common::SetCurrentThreadName("JoyconScanThread");
while (!stop_token.stop_requested()) {
do {
SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0); SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0);
SDL_hid_device_info* cur_dev = devs; SDL_hid_device_info* cur_dev = devs;
@ -81,8 +83,7 @@ void Joycons::ScanThread(std::stop_token stop_token) {
} }
SDL_hid_free_enumeration(devs); SDL_hid_free_enumeration(devs);
std::this_thread::sleep_for(std::chrono::seconds(5)); } while (Common::StoppableTimedWait(stop_token, std::chrono::seconds{5}));
}
} }
bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const { bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {