avoid potential race conditions during reset/etc by waiting till the emu thread got the message to pause
This commit is contained in:
parent
332282c809
commit
e298d50e76
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue