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.
This commit is contained in:
gblues 2017-12-30 20:59:07 -08:00
parent 11fed40c79
commit c2d2fe971e

View File

@ -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");