diff options
| author | 2021-10-23 23:32:16 +0200 | |
|---|---|---|
| committer | 2021-10-23 23:32:16 +0200 | |
| commit | 33e92c15ebf3f1cbfb48601108f3eaa70eefe18f (patch) | |
| tree | 685813e5c402326e30bba9daf6aff9d55cfb8b1a /src/input_common/gcadapter/gc_adapter.h | |
| parent | Merge pull request #6515 from german77/gc_thread_safe (diff) | |
| download | yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.gz yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.xz yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.zip | |
Revert "input_common: Fix data race on GC implementation"
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.h')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 46 |
1 files changed, 27 insertions, 19 deletions
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 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 7 | #include <algorithm> | 6 | #include <algorithm> |
| 8 | #include <functional> | 7 | #include <functional> |
| 9 | #include <mutex> | 8 | #include <mutex> |
| 10 | #include <stop_token> | ||
| 11 | #include <thread> | 9 | #include <thread> |
| 12 | #include <unordered_map> | 10 | #include <unordered_map> |
| 13 | |||
| 14 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 15 | #include "common/threadsafe_queue.h" | 12 | #include "common/threadsafe_queue.h" |
| 16 | #include "input_common/main.h" | 13 | #include "input_common/main.h" |
| @@ -21,9 +18,6 @@ struct libusb_device_handle; | |||
| 21 | 18 | ||
| 22 | namespace GCAdapter { | 19 | namespace GCAdapter { |
| 23 | 20 | ||
| 24 | class LibUSBContext; | ||
| 25 | class LibUSBDeviceHandle; | ||
| 26 | |||
| 27 | enum class PadButton { | 21 | enum class PadButton { |
| 28 | Undefined = 0x0000, | 22 | Undefined = 0x0000, |
| 29 | ButtonLeft = 0x0001, | 23 | ButtonLeft = 0x0001, |
| @@ -69,11 +63,11 @@ struct GCPadStatus { | |||
| 69 | }; | 63 | }; |
| 70 | 64 | ||
| 71 | struct GCController { | 65 | struct GCController { |
| 72 | ControllerTypes type = ControllerTypes::None; | 66 | ControllerTypes type{}; |
| 73 | bool enable_vibration = false; | 67 | bool enable_vibration{}; |
| 74 | u8 rumble_amplitude = 0; | 68 | u8 rumble_amplitude{}; |
| 75 | u16 buttons = 0; | 69 | u16 buttons{}; |
| 76 | PadButton last_button = PadButton::Undefined; | 70 | PadButton last_button{}; |
| 77 | std::array<s16, 6> axis_values{}; | 71 | std::array<s16, 6> axis_values{}; |
| 78 | std::array<u8, 6> axis_origin{}; | 72 | std::array<u8, 6> axis_origin{}; |
| 79 | u8 reset_origin_counter{}; | 73 | u8 reset_origin_counter{}; |
| @@ -115,9 +109,9 @@ private: | |||
| 115 | void UpdateStateAxes(std::size_t port, const AdapterPayload& adapter_payload); | 109 | void UpdateStateAxes(std::size_t port, const AdapterPayload& adapter_payload); |
| 116 | void UpdateVibrations(); | 110 | void UpdateVibrations(); |
| 117 | 111 | ||
| 118 | void AdapterInputThread(std::stop_token stop_token); | 112 | void AdapterInputThread(); |
| 119 | 113 | ||
| 120 | void AdapterScanThread(std::stop_token stop_token); | 114 | void AdapterScanThread(); |
| 121 | 115 | ||
| 122 | bool IsPayloadCorrect(const AdapterPayload& adapter_payload, s32 payload_size); | 116 | bool IsPayloadCorrect(const AdapterPayload& adapter_payload, s32 payload_size); |
| 123 | 117 | ||
| @@ -125,7 +119,13 @@ private: | |||
| 125 | void SendVibrations(); | 119 | void SendVibrations(); |
| 126 | 120 | ||
| 127 | /// For use in initialization, querying devices to find the adapter | 121 | /// For use in initialization, querying devices to find the adapter |
| 128 | bool Setup(); | 122 | void Setup(); |
| 123 | |||
| 124 | /// Resets status of all GC controller devices to a disconnected state | ||
| 125 | void ResetDevices(); | ||
| 126 | |||
| 127 | /// Resets status of device connected to a disconnected state | ||
| 128 | void ResetDevice(std::size_t port); | ||
| 129 | 129 | ||
| 130 | /// Returns true if we successfully gain access to GC Adapter | 130 | /// Returns true if we successfully gain access to GC Adapter |
| 131 | bool CheckDeviceAccess(); | 131 | bool CheckDeviceAccess(); |
| @@ -137,15 +137,23 @@ private: | |||
| 137 | /// For shutting down, clear all data, join all threads, release usb | 137 | /// For shutting down, clear all data, join all threads, release usb |
| 138 | void Reset(); | 138 | void Reset(); |
| 139 | 139 | ||
| 140 | std::unique_ptr<LibUSBDeviceHandle> usb_adapter_handle; | 140 | // Join all threads |
| 141 | void JoinThreads(); | ||
| 142 | |||
| 143 | // Release usb handles | ||
| 144 | void ClearLibusbHandle(); | ||
| 145 | |||
| 146 | libusb_device_handle* usb_adapter_handle = nullptr; | ||
| 141 | std::array<GCController, 4> pads; | 147 | std::array<GCController, 4> pads; |
| 142 | Common::SPSCQueue<GCPadStatus> pad_queue; | 148 | Common::SPSCQueue<GCPadStatus> pad_queue; |
| 143 | 149 | ||
| 144 | std::jthread adapter_input_thread; | 150 | std::thread adapter_input_thread; |
| 145 | std::jthread adapter_scan_thread; | 151 | std::thread adapter_scan_thread; |
| 146 | bool restart_scan_thread{}; | 152 | bool adapter_input_thread_running; |
| 153 | bool adapter_scan_thread_running; | ||
| 154 | bool restart_scan_thread; | ||
| 147 | 155 | ||
| 148 | std::unique_ptr<LibUSBContext> libusb_ctx; | 156 | libusb_context* libusb_ctx; |
| 149 | 157 | ||
| 150 | u8 input_endpoint{0}; | 158 | u8 input_endpoint{0}; |
| 151 | u8 output_endpoint{0}; | 159 | u8 output_endpoint{0}; |