Return correct errors in sceKernelDeleteThread().

And also, don't reschedule in sceKernelTerminateDeleteThread(), per tests.
This commit is contained in:
Unknown W. Brackets 2013-06-14 23:55:19 -07:00
parent ce2c18d2fe
commit 1e805e7fc8

View file

@ -2136,27 +2136,31 @@ int sceKernelRotateThreadReadyQueue(int priority)
return 0; 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; u32 error;
Thread *t = kernelObjects.Get<Thread>(threadHandle, error); Thread *t = kernelObjects.Get<Thread>(threadID, error);
if (t) if (t)
{
if (!t->isStopped())
{ {
// TODO: Should this reschedule ever? Probably no? ERROR_LOG(HLE, "sceKernelDeleteThread(%i): thread not dormant", threadID);
return __KernelDeleteThread(threadHandle, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread deleted", true); return SCE_KERNEL_ERROR_NOT_DORMANT;
} }
// TODO: Error when doesn't exist? DEBUG_LOG(HLE, "sceKernelDeleteThread(%i)", threadID);
return 0; return __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread deleted", true);
} }
else else
{ {
ERROR_LOG_REPORT(HLE, "Thread \"%s\" tries to delete itself! :(", __GetCurrentThread() ? __GetCurrentThread()->GetName() : "NULL"); ERROR_LOG(HLE, "sceKernelDeleteThread(%i): thread doesn't exist", threadID);
return -1; return error;
} }
} }
@ -2173,9 +2177,7 @@ int sceKernelTerminateDeleteThread(int threadID)
if (t) if (t)
{ {
INFO_LOG(HLE, "sceKernelTerminateDeleteThread(%i)", threadID); INFO_LOG(HLE, "sceKernelTerminateDeleteThread(%i)", threadID);
//TODO: should we really reschedule here? error = __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread terminated with delete", true);
error = __KernelDeleteThread(threadID, SCE_KERNEL_ERROR_THREAD_TERMINATED, "thread terminated with delete", false);
hleReSchedule("thread terminated with delete");
return error; return error;
} }