coreinit: add pause/resume functionality

This commit is contained in:
SSimco 2026-05-09 16:39:08 +03:00
parent bd076fe70a
commit 9f72963d64
4 changed files with 68 additions and 0 deletions

View File

@ -448,6 +448,8 @@ namespace CafeSystem
bool sSystemRunning = false;
TitleId sForegroundTitleId = 0;
bool sTitlePaused = false;
GameInfo2 sGameInfo_ForegroundTitle;
@ -931,6 +933,30 @@ namespace CafeSystem
return sSystemRunning;
}
void PauseTitle()
{
if (!sSystemRunning || sTitlePaused)
{
return;
}
sTitlePaused = true;
coreinit::SuspendActiveThreads();
}
void ResumeTitle()
{
if (!sSystemRunning || !sTitlePaused)
{
return;
}
sTitlePaused = false;
coreinit::ResumeActiveThreads();
}
TitleId GetForegroundTitleId()
{
cemu_assert_debug(sForegroundTitleId != 0);

View File

@ -31,6 +31,9 @@ namespace CafeSystem
void LaunchForegroundTitle();
bool IsTitleRunning();
void PauseTitle();
void ResumeTitle();
bool GetOverrideArgStr(std::vector<std::string>& args);
void SetOverrideArgs(std::span<std::string> args);
void UnsetOverrideArgs();

View File

@ -94,6 +94,42 @@ namespace coreinit
uint32 selectedCore;
};
void SuspendActiveThreads()
{
if (activeThreadCount == 0)
{
return;
}
__OSLockScheduler();
for (sint32 i = 0; i < activeThreadCount; i++)
{
auto thread = reinterpret_cast<OSThread_t*>(memory_getPointerFromVirtualOffset(activeThread[i]));
__OSSuspendThreadNolock(thread);
}
__OSUnlockScheduler();
}
void ResumeActiveThreads()
{
if (activeThreadCount == 0)
{
return;
}
__OSLockScheduler();
for (sint32 i = 0; i < activeThreadCount; i++)
{
auto thread = reinterpret_cast<OSThread_t*>(memory_getPointerFromVirtualOffset(activeThread[i]));
__OSResumeThreadInternal(thread, 1);
}
__OSUnlockScheduler();
}
std::unordered_map<OSThread_t*, OSHostThread*> s_threadToFiber;
bool __CemuIsMulticoreMode()

View File

@ -508,6 +508,9 @@ namespace coreinit
void InitializeConcurrency();
void SuspendActiveThreads();
void ResumeActiveThreads();
bool __CemuIsMulticoreMode();
OSThread_t* OSGetDefaultThread(sint32 coreIndex);