diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-22 01:33:18 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-22 01:33:18 +0200 |
commit | e298d50e76d9c37fbb8919b7a73327f036ade845 (patch) | |
tree | 292c15f2504fbc4ae6ab21d85cd9c65330d11953 | |
parent | 332282c8094d32d17282fd68da01ed9972177e06 (diff) |
avoid potential race conditions during reset/etc by waiting till the emu thread got the message to pause
-rw-r--r-- | src/libui_sdl/main.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 7ccc8f7..69e1bae 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -41,6 +41,7 @@ uiMenuItem* MenuItem_Stop; SDL_Thread* EmuThread; int EmuRunning; +volatile int EmuStatus; bool RunningSomething; char ROMPath[1024]; @@ -98,6 +99,8 @@ int EmuThreadFunc(void* burp) { if (EmuRunning == 1) { + EmuStatus = 1; + // emulate u32 nlines = NDS::RunFrame(); @@ -148,6 +151,8 @@ int EmuThreadFunc(void* burp) } else { + EmuStatus = 2; + // paused nframes = 0; lasttick = SDL_GetTicks(); @@ -160,6 +165,8 @@ int EmuThreadFunc(void* burp) } } + EmuStatus = 0; + if (audio) SDL_CloseAudioDevice(audio); NDS::DeInit(); @@ -269,6 +276,7 @@ void Run() void Stop() { EmuRunning = 2; + while (EmuStatus != 2); RunningSomething = false; uiMenuItemDisable(MenuItem_Pause); @@ -291,13 +299,14 @@ void OnCloseByMenu(uiMenuItem* item, uiWindow* window, void* blarg) { // TODO???? // uiQuit() crashes + printf("TODO, eventually\n"); } void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) { int prevstatus = EmuRunning; EmuRunning = 2; - // TODO: ensure the emu thread has indeed stopped at this point + while (EmuStatus != 2); char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", NULL); if (!file) @@ -350,6 +359,9 @@ void OnReset(uiMenuItem* item, uiWindow* window, void* blarg) { if (!RunningSomething) return; + EmuRunning = 2; + while (EmuStatus != 2); + if (ROMPath[0] == '\0') NDS::LoadBIOS(); else |