From 33e92c15ebf3f1cbfb48601108f3eaa70eefe18f Mon Sep 17 00:00:00 2001 From: Fernando S Date: Sat, 23 Oct 2021 23:32:16 +0200 Subject: Revert "input_common: Fix data race on GC implementation" --- src/input_common/gcadapter/gc_adapter.h | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 28dbcbe05..e5de5e94f 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -3,14 +3,11 @@ // Refer to the license.txt file included. #pragma once - #include #include #include -#include #include #include - #include "common/common_types.h" #include "common/threadsafe_queue.h" #include "input_common/main.h" @@ -21,9 +18,6 @@ struct libusb_device_handle; namespace GCAdapter { -class LibUSBContext; -class LibUSBDeviceHandle; - enum class PadButton { Undefined = 0x0000, ButtonLeft = 0x0001, @@ -69,11 +63,11 @@ struct GCPadStatus { }; struct GCController { - ControllerTypes type = ControllerTypes::None; - bool enable_vibration = false; - u8 rumble_amplitude = 0; - u16 buttons = 0; - PadButton last_button = PadButton::Undefined; + ControllerTypes type{}; + bool enable_vibration{}; + u8 rumble_amplitude{}; + u16 buttons{}; + PadButton last_button{}; std::array axis_values{}; std::array axis_origin{}; u8 reset_origin_counter{}; @@ -115,9 +109,9 @@ private: void UpdateStateAxes(std::size_t port, const AdapterPayload& adapter_payload); void UpdateVibrations(); - void AdapterInputThread(std::stop_token stop_token); + void AdapterInputThread(); - void AdapterScanThread(std::stop_token stop_token); + void AdapterScanThread(); bool IsPayloadCorrect(const AdapterPayload& adapter_payload, s32 payload_size); @@ -125,7 +119,13 @@ private: void SendVibrations(); /// For use in initialization, querying devices to find the adapter - bool Setup(); + void Setup(); + + /// Resets status of all GC controller devices to a disconnected state + void ResetDevices(); + + /// Resets status of device connected to a disconnected state + void ResetDevice(std::size_t port); /// Returns true if we successfully gain access to GC Adapter bool CheckDeviceAccess(); @@ -137,15 +137,23 @@ private: /// For shutting down, clear all data, join all threads, release usb void Reset(); - std::unique_ptr usb_adapter_handle; + // Join all threads + void JoinThreads(); + + // Release usb handles + void ClearLibusbHandle(); + + libusb_device_handle* usb_adapter_handle = nullptr; std::array pads; Common::SPSCQueue pad_queue; - std::jthread adapter_input_thread; - std::jthread adapter_scan_thread; - bool restart_scan_thread{}; + std::thread adapter_input_thread; + std::thread adapter_scan_thread; + bool adapter_input_thread_running; + bool adapter_scan_thread_running; + bool restart_scan_thread; - std::unique_ptr libusb_ctx; + libusb_context* libusb_ctx; u8 input_endpoint{0}; u8 output_endpoint{0}; -- cgit v1.2.3