From c2d2fe971e10ce394e5fadbdf8ff057b419c400a Mon Sep 17 00:00:00 2001 From: gblues Date: Sat, 30 Dec 2017 20:59:07 -0800 Subject: [PATCH] Add timeout for HID thread shutdown == DETAILS If a call to HIDRead() ends up blocking indefinitely, it will cause the shutdown process to wait forever. To avoid a deadlock, I've put in a retry counter so that it will give up after 5s and print a warning to the log. --- wiiu/input/wiiu_hid.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wiiu/input/wiiu_hid.c b/wiiu/input/wiiu_hid.c index 1c93c3cde9..f62eea43f9 100644 --- a/wiiu/input/wiiu_hid.c +++ b/wiiu/input/wiiu_hid.c @@ -425,6 +425,7 @@ static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, */ static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack) { int incomplete = 0; + int retries = 0; wiiu_adapter_t *adapter; RARCH_LOG("Waiting for in-flight reads to finish.\n"); do { @@ -446,8 +447,11 @@ static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack) { } OSFastMutex_Unlock(&(adapters.lock)); if(incomplete) { - RARCH_LOG("%d unfinished adapters found, waiting 1ms\n", incomplete); - usleep(1000); + usleep(5000); + } + if(++retries >= 1000) { + RARCH_WARN("[hid]: timed out waiting for in-flight read to finish.\n"); + incomplete = 0; } } while(incomplete); RARCH_LOG("All in-flight reads complete.\n");