From 1e805e7fc8ce58680286cc165e1a4db95f05671f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 14 Jun 2013 23:55:19 -0700 Subject: [PATCH] Return correct errors in sceKernelDeleteThread(). And also, don't reschedule in sceKernelTerminateDeleteThread(), per tests. --- Core/HLE/sceKernelThread.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 2859a9baaf..942ce0bd6f 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -2136,27 +2136,31 @@ int sceKernelRotateThreadReadyQueue(int priority) return 0; } -int sceKernelDeleteThread(int threadHandle) +int sceKernelDeleteThread(int threadID) { - if (threadHandle != currentThread) + if (threadID == 0 || threadID == currentThread) { - DEBUG_LOG(HLE,"sceKernelDeleteThread(%i)",threadHandle); + ERROR_LOG(HLE, "sceKernelDeleteThread(%i): cannot delete current thread", threadID); + return SCE_KERNEL_ERROR_NOT_DORMANT; + } - u32 error; - Thread *t = kernelObjects.Get(threadHandle, error); - if (t) + u32 error; + Thread *t = kernelObjects.Get(threadID, error); + if (t) + { + if (!t->isStopped()) { - // TODO: Should this reschedule ever? Probably no? - return __KernelDeleteThread(threadHandle, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread deleted", true); + ERROR_LOG(HLE, "sceKernelDeleteThread(%i): thread not dormant", threadID); + return SCE_KERNEL_ERROR_NOT_DORMANT; } - // TODO: Error when doesn't exist? - return 0; + DEBUG_LOG(HLE, "sceKernelDeleteThread(%i)", threadID); + return __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread deleted", true); } else { - ERROR_LOG_REPORT(HLE, "Thread \"%s\" tries to delete itself! :(", __GetCurrentThread() ? __GetCurrentThread()->GetName() : "NULL"); - return -1; + ERROR_LOG(HLE, "sceKernelDeleteThread(%i): thread doesn't exist", threadID); + return error; } } @@ -2173,9 +2177,7 @@ int sceKernelTerminateDeleteThread(int threadID) if (t) { INFO_LOG(HLE, "sceKernelTerminateDeleteThread(%i)", threadID); - //TODO: should we really reschedule here? - error = __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread terminated with delete", false); - hleReSchedule("thread terminated with delete"); + error = __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread terminated with delete", true); return error; }