From c11e46aeeacc876f5cab8982db18e9f045222e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 28 Sep 2026 15:16:31 -0600 Subject: [PATCH] LwMutex: Take the lock after a callback if it was released during it The end callback checked the kernel object's lockThread, which for an lwmutex is only refreshed by sceKernelReferLwMutexStatus. The lock state lives in the workarea, so an unlock during the callback left the waiter waiting forever. Verified against pspautotests threads/lwmutex/callbacks. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/sceKernelMutex.cpp | 3 ++- pspautotests | 2 +- test.py | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceKernelMutex.cpp b/Core/HLE/sceKernelMutex.cpp index 2044c88c06..da149aebba 100644 --- a/Core/HLE/sceKernelMutex.cpp +++ b/Core/HLE/sceKernelMutex.cpp @@ -826,7 +826,8 @@ static void __KernelWaitLwMutex(LwMutex *mutex, u32 timeoutPtr) { static bool __KernelUnlockLwMutexForThreadCheck(LwMutex *mutex, SceUID threadID, u32 &error, int result, bool &wokeThreads) { - if (mutex->nm.lockThread == -1 && __KernelUnlockLwMutexForThread(mutex, mutex->nm.workarea, threadID, error, 0)) + // The lock state lives in the workarea, nm.lockThread is only refreshed when referred. + if (mutex->nm.workarea->lockLevel == 0 && __KernelUnlockLwMutexForThread(mutex, mutex->nm.workarea, threadID, error, 0)) return true; return false; } diff --git a/pspautotests b/pspautotests index d2097ed7d8..33e59e29f2 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit d2097ed7d840d39dddf37433726790cd2a446a1d +Subproject commit 33e59e29f2aad3c7440e5b1afeab1715268d72dc diff --git a/test.py b/test.py index 7515cbd36b..61af594c53 100755 --- a/test.py +++ b/test.py @@ -345,6 +345,7 @@ tests_good = [ "threads/fpl/refer", "threads/fpl/tryallocate", "threads/k0/k0", + "threads/lwmutex/callbacks", "threads/lwmutex/create", "threads/lwmutex/delete", "threads/lwmutex/lock",