Skip to content

Commit

Permalink
Wrap the sleep/wakeup HLE funcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed May 26, 2013
1 parent 8adf1e9 commit 084ad5a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ const HLEFunction ThreadManForUser[] =
{0xA9C2CB9A,&WrapI_IU<sceKernelReferMutexStatus>, "sceKernelReferMutexStatus"},
{0x87D9223C,0, "sceKernelCancelMutex"},

{0xFCCFAD26,sceKernelCancelWakeupThread,"sceKernelCancelWakeupThread"},
{0xFCCFAD26,WrapI_I<sceKernelCancelWakeupThread>,"sceKernelCancelWakeupThread"},
{0x1AF94D03,0,"sceKernelDonateWakeupThread"},
{0xea748e31,sceKernelChangeCurrentThreadAttr,"sceKernelChangeCurrentThreadAttr"},
{0x71bc9871,sceKernelChangeThreadPriority,"sceKernelChangeThreadPriority"},
Expand All @@ -696,8 +696,8 @@ const HLEFunction ThreadManForUser[] =
{0x3ad58b8c,&WrapU_V<sceKernelSuspendDispatchThread>,"sceKernelSuspendDispatchThread"},
{0x27e22ec2,&WrapU_U<sceKernelResumeDispatchThread>,"sceKernelResumeDispatchThread"},
{0x912354a7,&WrapI_I<sceKernelRotateThreadReadyQueue>,"sceKernelRotateThreadReadyQueue"},
{0x9ACE131E,sceKernelSleepThread,"sceKernelSleepThread"},
{0x82826f70,sceKernelSleepThreadCB,"sceKernelSleepThreadCB"},
{0x9ACE131E,WrapI_V<sceKernelSleepThread>,"sceKernelSleepThread"},
{0x82826f70,WrapI_V<sceKernelSleepThreadCB>,"sceKernelSleepThreadCB"},
{0xF475845D,&WrapI_IIU<sceKernelStartThread>,"sceKernelStartThread"},
{0x9944f31f,sceKernelSuspendThread,"sceKernelSuspendThread"},
{0x616403ba,WrapI_I<sceKernelTerminateThread>,"sceKernelTerminateThread"},
Expand Down Expand Up @@ -731,7 +731,7 @@ const HLEFunction ThreadManForUser[] =
{0xE1619D7C,WrapI_UUUU<sceKernelSysClock2USecWide>,"sceKernelSysClock2USecWide"},

{0x278C0DF5,WrapI_IU<sceKernelWaitThreadEnd>,"sceKernelWaitThreadEnd"},
{0xd59ead2f,sceKernelWakeupThread,"sceKernelWakeupThread"}, //AI Go, audio?
{0xd59ead2f,WrapI_I<sceKernelWakeupThread>,"sceKernelWakeupThread"}, //AI Go, audio?

{0x0C106E53,0,"sceKernelRegisterThreadEventHandler"},
{0x72F3C145,0,"sceKernelReleaseThreadEventHandler"},
Expand Down
3 changes: 0 additions & 3 deletions Core/HLE/sceKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,6 @@ void sceKernelExitGameWithStatus();
int LoadExecForUser_362A956B();
void sceKernelRegisterExitCallback();

void sceKernelSleepThread();
void sceKernelSleepThreadCB();

u32 sceKernelDevkitVersion();

u32 sceKernelRegisterKprintfHandler();
Expand Down
35 changes: 15 additions & 20 deletions Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2334,33 +2334,30 @@ bool __KernelThreadSortPriority(SceUID thread1, SceUID thread2)
//////////////////////////////////////////////////////////////////////////
// WAIT/SLEEP ETC
//////////////////////////////////////////////////////////////////////////
void sceKernelWakeupThread()
int sceKernelWakeupThread(SceUID uid)
{
SceUID uid = PARAM(0);
u32 error;
Thread *t = kernelObjects.Get<Thread>(uid, error);
if (t)
{
if (!t->isWaitingFor(WAITTYPE_SLEEP, 1)) {
t->nt.wakeupCount++;
DEBUG_LOG(HLE,"sceKernelWakeupThread(%i) - wakeupCount incremented to %i", uid, t->nt.wakeupCount);
RETURN(0);
} else {
VERBOSE_LOG(HLE,"sceKernelWakeupThread(%i) - woke thread at %i", uid, t->nt.wakeupCount);
__KernelResumeThreadFromWait(uid);
hleReSchedule("thread woken up");
RETURN(0);
}
return 0;
}
else {
ERROR_LOG(HLE,"sceKernelWakeupThread(%i) - bad thread id", uid);
RETURN(error);
return error;
}
}

void sceKernelCancelWakeupThread()
int sceKernelCancelWakeupThread(SceUID uid)
{
SceUID uid = PARAM(0);
u32 error;
if (uid == 0) uid = __KernelGetCurThread();
Thread *t = kernelObjects.Get<Thread>(uid, error);
Expand All @@ -2369,44 +2366,42 @@ void sceKernelCancelWakeupThread()
int wCount = t->nt.wakeupCount;
t->nt.wakeupCount = 0;
DEBUG_LOG(HLE,"sceKernelCancelWakeupThread(%i) - wakeupCount reset from %i", uid, wCount);
RETURN(wCount);
return wCount;
}
else {
ERROR_LOG(HLE,"sceKernelCancelWakeupThread(%i) - bad thread id", uid);
RETURN(error);
return error;
}
}

static void __KernelSleepThread(bool doCallbacks) {
static int __KernelSleepThread(bool doCallbacks) {
Thread *thread = __GetCurrentThread();
if (!thread)
{
if (!thread) {
ERROR_LOG(HLE, "sceKernelSleepThread*(): bad current thread");
return;
return -1;
}

if (thread->nt.wakeupCount > 0) {
thread->nt.wakeupCount--;
DEBUG_LOG(HLE, "sceKernelSleepThread() - wakeupCount decremented to %i", thread->nt.wakeupCount);
RETURN(0);
} else {
VERBOSE_LOG(HLE, "sceKernelSleepThread()");
RETURN(0);
__KernelWaitCurThread(WAITTYPE_SLEEP, 1, 0, 0, doCallbacks, "thread slept");
}
return 0;
}

void sceKernelSleepThread()
int sceKernelSleepThread()
{
__KernelSleepThread(false);
return __KernelSleepThread(false);
}

//the homebrew PollCallbacks
void sceKernelSleepThreadCB()
int sceKernelSleepThreadCB()
{
VERBOSE_LOG(HLE, "sceKernelSleepThreadCB()");
__KernelSleepThread(true);
__KernelCheckCallbacks();
hleCheckCurrentCallbacks();
return __KernelSleepThread(true);
}

int sceKernelWaitThreadEnd(SceUID threadID, u32 timeoutPtr)
Expand Down
6 changes: 4 additions & 2 deletions Core/HLE/sceKernelThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ int sceKernelRotateThreadReadyQueue(int priority);
int sceKernelCheckThreadStack();
void sceKernelSuspendThread();
void sceKernelResumeThread();
void sceKernelWakeupThread();
void sceKernelCancelWakeupThread();
int sceKernelWakeupThread(SceUID threadID);
int sceKernelCancelWakeupThread(SceUID threadID);
int sceKernelSleepThread();
int sceKernelSleepThreadCB();
int sceKernelTerminateDeleteThread(int threadno);
int sceKernelTerminateThread(SceUID threadID);
int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr);
Expand Down

0 comments on commit 084ad5a

Please sign in to comment.