Cleaner exit from emuthread, as used by OpenGL. Don't know how it worked before...

This commit is contained in:
Henrik Rydgård 2022-11-08 21:59:08 +01:00
parent a0c893cc8f
commit 436a3e0d61
5 changed files with 17 additions and 10 deletions

View File

@ -247,6 +247,7 @@ void GLRenderManager::StopThread() {
GLRRenderThreadTask exitTask{};
exitTask.runType = GLRRunType::EXIT;
renderThreadQueue_.push(exitTask);
pushCondVar_.notify_one();
} else {
WARN_LOG(G3D, "GL submission thread was already paused.");
}

View File

@ -437,7 +437,7 @@ public:
// We pass in width/height here even though it's not strictly needed until we support glTextureStorage
// and then we'll also need formats and stuff.
GLRTexture *CreateTexture(GLenum target, int width, int height, int depth, int numMips) {
GLRInitStep step{ GLRInitStepType::CREATE_TEXTURE };
GLRInitStep step { GLRInitStepType::CREATE_TEXTURE };
step.create_texture.texture = new GLRTexture(caps_, width, height, depth, numMips);
step.create_texture.texture->target = target;
initSteps_.push_back(step);

View File

@ -328,14 +328,14 @@ void Core_ProcessStepping() {
// Many platforms, like Android, do not call this function but handle things on their own.
// Instead they simply call NativeRender and NativeUpdate directly.
void Core_Run(GraphicsContext *ctx) {
bool Core_Run(GraphicsContext *ctx) {
host->UpdateDisassembly();
while (true) {
if (GetUIState() != UISTATE_INGAME) {
Core_StateProcessed();
if (GetUIState() == UISTATE_EXIT) {
UpdateRunLoop();
return;
return false;
}
Core_RunLoop(ctx);
continue;
@ -348,7 +348,7 @@ void Core_Run(GraphicsContext *ctx) {
Core_RunLoop(ctx);
if (coreState == CORE_POWERDOWN) {
Core_StateProcessed();
return;
return true;
}
break;
@ -359,10 +359,10 @@ void Core_Run(GraphicsContext *ctx) {
// Exit loop!!
Core_StateProcessed();
return;
return true;
case CORE_NEXTFRAME:
return;
return true;
}
}
}

View File

@ -27,8 +27,10 @@ class GraphicsContext;
// called from emu thread
void UpdateRunLoop();
void Core_Run(GraphicsContext *ctx);
// Returns false when an UI exit state is detected.
bool Core_Run(GraphicsContext *ctx);
void Core_Stop();
// For platforms that don't call Core_Run
void Core_SetGraphicsContext(GraphicsContext *ctx);

View File

@ -82,7 +82,9 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) {
// This way they can load a new game.
if (!Core_IsActive())
UpdateUIState(UISTATE_MENU);
Core_Run(g_graphicsContext);
if (!Core_Run(g_graphicsContext)) {
emuThreadState = (int)EmuThreadState::QUIT_REQUESTED;
}
}
emuThreadState = (int)EmuThreadState::STOPPED;
@ -99,12 +101,14 @@ static void EmuThreadStart(GraphicsContext *graphicsContext) {
}
static void EmuThreadStop() {
emuThreadState = (int)EmuThreadState::QUIT_REQUESTED;
if (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED &&
emuThreadState != (int)EmuThreadState::STOPPED) {
emuThreadState = (int)EmuThreadState::QUIT_REQUESTED;
}
}
static void EmuThreadJoin() {
emuThread.join();
emuThread = std::thread();
INFO_LOG(SYSTEM, "EmuThreadJoin - joined");
}