From 065fb7eb58855ec2d8c009f2dfabc3e815b91915 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Mon, 6 May 2024 09:15:36 +0200 Subject: [PATCH] coreinit: Add reschedule special case to avoid a deadlock Fixes Just Dance 2019 locking up on boot --- src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp index 533360aa..fbf498db 100644 --- a/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp +++ b/src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp @@ -763,6 +763,11 @@ namespace coreinit uint32 coreIndex = OSGetCoreId(); if (!newThread->context.hasCoreAffinitySet(coreIndex)) return false; + // special case: if current and new thread are running only on the same core then reschedule even if priority is equal + // this resolves a deadlock in Just Dance 2019 where one thread would always reacquire the same mutex within it's timeslice, blocking another thread on the same core from acquiring it + if ((1<context.affinity && currentThread->context.affinity == newThread->context.affinity && currentThread->effectivePriority == newThread->effectivePriority) + return true; + // otherwise reschedule if new thread has higher priority return newThread->effectivePriority < currentThread->effectivePriority; }