Make sure the cpu thread ends on Core_Stop().

Sometimes it didn't, which was just a bit confusing.
This commit is contained in:
Unknown W. Brackets 2013-10-12 10:55:31 -07:00
parent 585f86c805
commit a79b168acc

View File

@ -95,23 +95,31 @@ bool IsOnSeparateCPUThread() {
} }
} }
void CPU_SetState(CPUThreadState to) {
lock_guard guard(cpuThreadLock);
cpuThreadState = to;
cpuThreadCond.notify_one();
cpuThreadReplyCond.notify_one();
}
bool CPU_NextState(CPUThreadState from, CPUThreadState to) { bool CPU_NextState(CPUThreadState from, CPUThreadState to) {
lock_guard guard(cpuThreadLock); lock_guard guard(cpuThreadLock);
if (cpuThreadState == from) { if (cpuThreadState == from) {
cpuThreadState = to; CPU_SetState(to);
cpuThreadCond.notify_one();
cpuThreadReplyCond.notify_one();
return true; return true;
} else { } else {
return false; return false;
} }
} }
void CPU_SetState(CPUThreadState to) { bool CPU_NextStateNot(CPUThreadState from, CPUThreadState to) {
lock_guard guard(cpuThreadLock); lock_guard guard(cpuThreadLock);
cpuThreadState = to; if (cpuThreadState != from) {
cpuThreadCond.notify_one(); CPU_SetState(to);
cpuThreadReplyCond.notify_one(); return true;
} else {
return false;
}
} }
bool CPU_IsReady() { bool CPU_IsReady() {
@ -261,8 +269,13 @@ void Core_UpdateState(CoreState newState) {
} }
void System_Wake() { void System_Wake() {
if (CPU_IsReady()) {
CPU_NextStateNot(CPU_THREAD_NOT_RUNNING, CPU_THREAD_SHUTDOWN);
CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsShutdown);
}
if (gpu) { if (gpu) {
gpu->FinishEventLoop(); gpu->FinishEventLoop();
gpu->SyncThread();
} }
} }
@ -302,7 +315,7 @@ void PSP_Shutdown() {
Core_UpdateState(CORE_ERROR); Core_UpdateState(CORE_ERROR);
Core_NotifyShutdown(); Core_NotifyShutdown();
if (cpuThread != NULL) { if (cpuThread != NULL) {
CPU_SetState(CPU_THREAD_SHUTDOWN); CPU_NextStateNot(CPU_THREAD_NOT_RUNNING, CPU_THREAD_SHUTDOWN);
CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsShutdown); CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsShutdown);
delete cpuThread; delete cpuThread;
cpuThread = 0; cpuThread = 0;