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.
This commit is contained in:
nyanpasu64 2023-06-18 14:28:26 -07:00
parent afb5eff426
commit 559a16da49
1 changed files with 12 additions and 4 deletions

View File

@ -203,9 +203,8 @@ static void ReadThreadFunc()
std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> 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);