From 48c5efd0c2f2a9cb1a6783dc10574349eb278140 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 30 Nov 2012 22:20:14 -0800 Subject: [PATCH] Match hw timing of mutex/sema timeouts better. Affects some tests passing/not passing due to minor timing issues, ugh. --- Core/HLE/sceKernelMutex.cpp | 9 ++++++++- Core/HLE/sceKernelSemaphore.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceKernelMutex.cpp b/Core/HLE/sceKernelMutex.cpp index 5a11d33e08..8a0224cb7d 100644 --- a/Core/HLE/sceKernelMutex.cpp +++ b/Core/HLE/sceKernelMutex.cpp @@ -685,8 +685,15 @@ void __KernelWaitLwMutex(LwMutex *mutex, u32 timeoutPtr) if (timeoutPtr == 0 || lwMutexWaitTimer == 0) return; - // This should call __KernelMutexTimeout() later, unless we cancel it. int micro = (int) Memory::Read_U32(timeoutPtr); + + // This happens to be how the hardware seems to time things. + if (micro <= 3) + micro = 15; + else if (micro <= 249) + micro = 250; + + // This should call __KernelMutexTimeout() later, unless we cancel it. CoreTiming::ScheduleEvent(usToCycles(micro), lwMutexWaitTimer, __KernelGetCurThread()); } diff --git a/Core/HLE/sceKernelSemaphore.cpp b/Core/HLE/sceKernelSemaphore.cpp index fdd19b94b7..ccbc46c035 100644 --- a/Core/HLE/sceKernelSemaphore.cpp +++ b/Core/HLE/sceKernelSemaphore.cpp @@ -301,8 +301,15 @@ void __KernelSetSemaTimeout(Semaphore *s, u32 timeoutPtr) if (timeoutPtr == 0 || semaWaitTimer == 0) return; - // This should call __KernelMutexTimeout() later, unless we cancel it. int micro = (int) Memory::Read_U32(timeoutPtr); + + // This happens to be how the hardware seems to time things. + if (micro <= 3) + micro = 15; + else if (micro <= 249) + micro = 250; + + // This should call __KernelSemaTimeout() later, unless we cancel it. CoreTiming::ScheduleEvent(usToCycles(micro), semaWaitTimer, __KernelGetCurThread()); }