From 56053e81050a15e38b768b0798727404bf852e7a Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sun, 21 Apr 2024 13:27:06 +0200 Subject: [PATCH] gamecard: add smarter delay to detection thread Lets us respond in a better way to sudden gamecard status changes during the 3 second wait period. --- source/core/gamecard.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/source/core/gamecard.c b/source/core/gamecard.c index 26a9dd56..c266853e 100644 --- a/source/core/gamecard.c +++ b/source/core/gamecard.c @@ -695,17 +695,29 @@ static void gamecardDetectionThreadFunc(void *arg) /* Free gamecard info before proceeding. */ gamecardFreeInfo(true); - /* Retrieve current gamecard insertion status. */ - /* Only proceed if we're dealing with a status change. */ - if (gamecardIsInserted()) + /* Delay gamecard access by GAMECARD_ACCESS_DELAY full seconds. This is done to to avoid conflicts with HOS / sysmodules. */ + /* We will periodically check if the gamecard is still inserted during this period. */ + /* If the gamecard is taken out before reaching the length of the delay, we won't try to access it. */ + time_t start = time(NULL); + bool gc_delay_passed = false; + + while(gamecardIsInserted()) { - /* Don't access the gamecard immediately to avoid conflicts with HOS / sysmodules. */ - utilsSleep(GAMECARD_ACCESS_DELAY); + time_t now = time(NULL); + time_t diff = (now - start); + + if (diff >= GAMECARD_ACCESS_DELAY) + { + gc_delay_passed = true; + break; + } - /* Load gamecard info. */ - gamecardLoadInfo(); + utilsAppletLoopDelay(); } + /* Load gamecard info (if applicable). */ + if (gc_delay_passed) gamecardLoadInfo(); + /* Signal user mode gamecard status change event. */ ueventSignal(&g_gameCardStatusChangeEvent); }