Changed the way the emulator is shut down, fixes #1555.

This commit is contained in:
OBattler
2021-07-21 04:05:40 +02:00
parent 803ae780ac
commit 706ad0e896
5 changed files with 24 additions and 23 deletions

View File

@@ -85,7 +85,7 @@
and declared here instead. */ and declared here instead. */
int dopause; /* system is paused */ int dopause; /* system is paused */
int doresize; /* screen resize requested */ int doresize; /* screen resize requested */
int is_quit; /* system exit requested */ volatile int is_quit; /* system exit requested */
uint64_t timer_freq; uint64_t timer_freq;
char emu_version[200]; /* version ID string */ char emu_version[200]; /* version ID string */
@@ -919,14 +919,8 @@ pc_close(thread_t *ptr)
/* Claim the video blitter. */ /* Claim the video blitter. */
startblit(); startblit();
/* Terminate the main thread. */ /* Terminate the UI thread. */
if (ptr != NULL) {
is_quit = 1; is_quit = 1;
thread_wait(ptr, -1);
/* Wait some more. */
plat_delay_ms(200);
}
#if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) #if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC))
codegen_close(); codegen_close();

View File

@@ -189,6 +189,8 @@ extern void resub_cycles(int old_cycles);
extern double isa_timing; extern double isa_timing;
extern int io_delay, framecountx; extern int io_delay, framecountx;
extern volatile int cpu_thread_run;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -64,8 +64,8 @@ extern "C" {
/* Global variables residing in the platform module. */ /* Global variables residing in the platform module. */
extern int dopause, /* system is paused */ extern int dopause, /* system is paused */
doresize, /* screen resize requested */ doresize, /* screen resize requested */
is_quit, /* system exit requested */
mouse_capture; /* mouse is captured in app */ mouse_capture; /* mouse is captured in app */
extern volatile int is_quit; /* system exit requested */
#ifdef MTR_ENABLED #ifdef MTR_ENABLED
extern int tracing_on; extern int tracing_on;

View File

@@ -69,6 +69,7 @@ HANDLE ghMutex;
LCID lang_id; /* current language ID used */ LCID lang_id; /* current language ID used */
DWORD dwSubLangID; DWORD dwSubLangID;
int acp_utf8; /* Windows supports UTF-8 codepage */ int acp_utf8; /* Windows supports UTF-8 codepage */
volatile int cpu_thread_run = 1;
/* Local data. */ /* Local data. */
@@ -487,7 +488,7 @@ main_thread(void *param)
title_update = 1; title_update = 1;
old_time = GetTickCount(); old_time = GetTickCount();
drawits = frames = 0; drawits = frames = 0;
while (!is_quit) { while (!is_quit && cpu_thread_run) {
/* See if it is time to run a frame of code. */ /* See if it is time to run a frame of code. */
new_time = GetTickCount(); new_time = GetTickCount();
drawits += (new_time - old_time); drawits += (new_time - old_time);
@@ -511,7 +512,7 @@ main_thread(void *param)
Sleep(1); Sleep(1);
/* If needed, handle a screen resize. */ /* If needed, handle a screen resize. */
if (doresize && !video_fullscreen) { if (doresize && !video_fullscreen && !is_quit) {
if (vid_resize & 2) if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y); plat_resize(fixed_size_x, fixed_size_y);
else else
@@ -519,6 +520,8 @@ main_thread(void *param)
doresize = 0; doresize = 0;
} }
} }
is_quit = 1;
} }
@@ -551,16 +554,17 @@ do_start(void)
void void
do_stop(void) do_stop(void)
{ {
is_quit = 1; /* Claim the video blitter. */
startblit();
plat_delay_ms(100); vid_apis[vid_api].close();
if (source_hwnd)
PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain);
pc_close(thMain); pc_close(thMain);
thMain = NULL; thMain = NULL;
if (source_hwnd)
PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain);
} }

View File

@@ -477,9 +477,10 @@ plat_power_off(void)
/* Cleanly terminate all of the emulator's components so as /* Cleanly terminate all of the emulator's components so as
to avoid things like threads getting stuck. */ to avoid things like threads getting stuck. */
do_stop(); // do_stop();
cpu_thread_run = 0;
exit(-1); // exit(-1);
} }
#ifdef MTR_ENABLED #ifdef MTR_ENABLED
@@ -1547,10 +1548,10 @@ ui_init(int nCmdShow)
fatal("bRet is -1\n"); fatal("bRet is -1\n");
} }
if (messages.message == WM_QUIT) { /* On WM_QUIT, tell the CPU thread to stop running. That will then tell us
is_quit = 1; to stop running as well. */
break; if (messages.message == WM_QUIT)
} cpu_thread_run = 0;
if (! TranslateAccelerator(hwnd, haccel, &messages)) if (! TranslateAccelerator(hwnd, haccel, &messages))
{ {