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

View File

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

View File

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

View File

@@ -69,6 +69,7 @@ HANDLE ghMutex;
LCID lang_id; /* current language ID used */
DWORD dwSubLangID;
int acp_utf8; /* Windows supports UTF-8 codepage */
volatile int cpu_thread_run = 1;
/* Local data. */
@@ -487,7 +488,7 @@ main_thread(void *param)
title_update = 1;
old_time = GetTickCount();
drawits = frames = 0;
while (!is_quit) {
while (!is_quit && cpu_thread_run) {
/* See if it is time to run a frame of code. */
new_time = GetTickCount();
drawits += (new_time - old_time);
@@ -511,7 +512,7 @@ main_thread(void *param)
Sleep(1);
/* If needed, handle a screen resize. */
if (doresize && !video_fullscreen) {
if (doresize && !video_fullscreen && !is_quit) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
else
@@ -519,6 +520,8 @@ main_thread(void *param)
doresize = 0;
}
}
is_quit = 1;
}
@@ -551,16 +554,17 @@ do_start(void)
void
do_stop(void)
{
is_quit = 1;
/* Claim the video blitter. */
startblit();
plat_delay_ms(100);
if (source_hwnd)
PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain);
vid_apis[vid_api].close();
pc_close(thMain);
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
to avoid things like threads getting stuck. */
do_stop();
// do_stop();
cpu_thread_run = 0;
exit(-1);
// exit(-1);
}
#ifdef MTR_ENABLED
@@ -1547,10 +1548,10 @@ ui_init(int nCmdShow)
fatal("bRet is -1\n");
}
if (messages.message == WM_QUIT) {
is_quit = 1;
break;
}
/* On WM_QUIT, tell the CPU thread to stop running. That will then tell us
to stop running as well. */
if (messages.message == WM_QUIT)
cpu_thread_run = 0;
if (! TranslateAccelerator(hwnd, haccel, &messages))
{