From 559a16da4999c1159bb4d594a969f13e77100a1c Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sun, 18 Jun 2023 14:28:26 -0700 Subject: [PATCH] Reset GC adapter upon IO error after sleep-wake Fixes GC adapter breaking on sleep-wake on Linux and burning a full CPU core. This is cleaner than alternative approaches. --- Source/Core/InputCommon/GCAdapter.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index cacb73bc79..6088256a55 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -203,9 +203,8 @@ static void ReadThreadFunc() std::array input_buffer; int payload_size = 0; - const int error = - libusb_interrupt_transfer(s_handle, s_endpoint_in, input_buffer.data(), - int(input_buffer.size()), &payload_size, USB_TIMEOUT_MS); + int error = libusb_interrupt_transfer(s_handle, s_endpoint_in, input_buffer.data(), + int(input_buffer.size()), &payload_size, USB_TIMEOUT_MS); if (error != LIBUSB_SUCCESS) { ERROR_LOG_FMT(CONTROLLERINTERFACE, "Read: libusb_interrupt_transfer failed: {}", @@ -213,7 +212,16 @@ static void ReadThreadFunc() } if (error == LIBUSB_ERROR_IO) { - break; + // s_read_adapter_thread_running is cleared by the joiner, not the stopper. + + // Reset the device, which may trigger a replug. + error = libusb_reset_device(s_handle); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Read: libusb_reset_device: {}", + LibusbUtils::ErrorWrap(error)); + if (error != 0) + { + break; + } } ProcessInputPayload(input_buffer.data(), payload_size);