mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-26 07:43:36 +01:00
Allow switching cpu thread on/off ingame.
This commit is contained in:
1 parent
71c9804ffd
commit
0a6a70f53f
6 files changed
+47
-15
No files matched your search
+39
-8
@@ -63,8 +63,10 @@ enum CPUThreadState {
|
||||
CPU_THREAD_STARTING,
|
||||
CPU_THREAD_RUNNING,
|
||||
CPU_THREAD_SHUTDOWN,
|
||||
CPU_THREAD_QUIT,
|
||||
|
||||
CPU_THREAD_EXECUTE,
|
||||
CPU_THREAD_RESUME,
|
||||
};
|
||||
|
||||
MetaFileSystem pspFileSystem;
|
||||
@@ -73,7 +75,7 @@ static GlobalUIState globalUIState;
|
||||
static CoreParameter coreParameter;
|
||||
static FileLoader *loadedFile;
|
||||
static PSPMixer *mixer;
|
||||
static std::thread *cpuThread = NULL;
|
||||
static std::thread *cpuThread = nullptr;
|
||||
static std::thread::id cpuThreadID;
|
||||
static recursive_mutex cpuThreadLock;
|
||||
static condition_variable cpuThreadCond;
|
||||
@@ -110,7 +112,7 @@ void Audio_Init() {
|
||||
}
|
||||
|
||||
bool IsOnSeparateCPUThread() {
|
||||
if (cpuThread != NULL) {
|
||||
if (cpuThread != nullptr) {
|
||||
return cpuThreadID == std::this_thread::get_id();
|
||||
} else {
|
||||
return false;
|
||||
@@ -269,14 +271,14 @@ void CPU_RunLoop() {
|
||||
setCurrentThreadName("CPU");
|
||||
FPU_SetFastMode();
|
||||
|
||||
if (!CPU_NextState(CPU_THREAD_PENDING, CPU_THREAD_STARTING)) {
|
||||
if (CPU_NextState(CPU_THREAD_PENDING, CPU_THREAD_STARTING)) {
|
||||
CPU_Init();
|
||||
CPU_NextState(CPU_THREAD_STARTING, CPU_THREAD_RUNNING);
|
||||
} else if (!CPU_NextState(CPU_THREAD_RESUME, CPU_THREAD_RUNNING)) {
|
||||
ERROR_LOG(CPU, "CPU thread in unexpected state: %d", cpuThreadState);
|
||||
return;
|
||||
}
|
||||
|
||||
CPU_Init();
|
||||
CPU_NextState(CPU_THREAD_STARTING, CPU_THREAD_RUNNING);
|
||||
|
||||
while (cpuThreadState != CPU_THREAD_SHUTDOWN)
|
||||
{
|
||||
CPU_WaitStatus(cpuThreadCond, &CPU_HasPendingAction);
|
||||
@@ -292,6 +294,11 @@ void CPU_RunLoop() {
|
||||
case CPU_THREAD_SHUTDOWN:
|
||||
break;
|
||||
|
||||
case CPU_THREAD_QUIT:
|
||||
// Just leave the thread, CPU is switching off thread.
|
||||
CPU_SetState(CPU_THREAD_NOT_RUNNING);
|
||||
return;
|
||||
|
||||
default:
|
||||
ERROR_LOG(CPU, "CPU thread in unexpected state: %d", cpuThreadState);
|
||||
// Begin shutdown, otherwise we'd just spin on this bad state.
|
||||
@@ -426,7 +433,7 @@ void PSP_Shutdown() {
|
||||
if (coreState == CORE_RUNNING)
|
||||
Core_UpdateState(CORE_ERROR);
|
||||
Core_NotifyShutdown();
|
||||
if (cpuThread != NULL) {
|
||||
if (cpuThread != nullptr) {
|
||||
CPU_NextStateNot(CPU_THREAD_NOT_RUNNING, CPU_THREAD_SHUTDOWN);
|
||||
CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsShutdown);
|
||||
delete cpuThread;
|
||||
@@ -451,7 +458,31 @@ void PSP_RunLoopUntil(u64 globalticks) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cpuThread != NULL) {
|
||||
// Switch the CPU thread on or off, as the case may be.
|
||||
bool useCPUThread = g_Config.bSeparateCPUThread;
|
||||
if (useCPUThread && cpuThread == nullptr) {
|
||||
// Need to start the cpu thread.
|
||||
Core_ListenShutdown(System_Wake);
|
||||
CPU_SetState(CPU_THREAD_RESUME);
|
||||
cpuThread = new std::thread(&CPU_RunLoop);
|
||||
cpuThreadID = cpuThread->get_id();
|
||||
cpuThread->detach();
|
||||
if (gpu) {
|
||||
gpu->SetThreadEnabled(true);
|
||||
}
|
||||
CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsReady);
|
||||
} else if (!useCPUThread && cpuThread != nullptr) {
|
||||
CPU_SetState(CPU_THREAD_QUIT);
|
||||
CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsShutdown);
|
||||
delete cpuThread;
|
||||
cpuThread = nullptr;
|
||||
cpuThreadID = std::thread::id();
|
||||
if (gpu) {
|
||||
gpu->SetThreadEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (cpuThread != nullptr) {
|
||||
// Tell the gpu a new frame is about to begin, before we start the CPU.
|
||||
gpu->SyncBeginFrame();
|
||||
|
||||
|
||||
Reference in new issue
Block a user