From 2787bc61aadf7507cdfe89077e120c3ffa1c789c Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 23 Jan 2024 07:58:45 +1000 Subject: [PATCH] sys: refactor the clean shutdown process After all the other refactors finally we can clean this up. Signed-off-by: bones_was_here --- host.c | 22 +++++----------------- host.h | 1 - sys.h | 1 - sys_shared.c | 38 ++++++++++---------------------------- 4 files changed, 15 insertions(+), 47 deletions(-) diff --git a/host.c b/host.c index bb1b83fc..a2c43d85 100644 --- a/host.c +++ b/host.c @@ -574,25 +574,13 @@ static void Host_Init (void) =============== Host_Shutdown -FIXME: this is a callback from Sys_Quit(). It would be better -to run quit through here before the final handoff to the sys code. +Cleanly shuts down after the main loop exits. =============== */ -void Host_Shutdown(void) +static void Host_Shutdown(void) { - static qbool isdown = false; - - if (isdown) - { - Con_Print(CON_WARN "recursive shutdown\n"); - return; - } - if (setjmp(host.abortframe)) - { - Con_Print(CON_WARN "aborted the quitting frame?!?\n"); - return; - } - isdown = true; + if (Sys_CheckParm("-profilegameonly")) + Sys_AllowProfiling(false); if(cls.state != ca_dedicated) CL_Shutdown(); @@ -725,5 +713,5 @@ void Host_Main(void) host.sleeptime = Sys_Sleep(sleeptime); } - return; + Host_Shutdown(); } diff --git a/host.h b/host.h index 78bd8083..89ea1f11 100644 --- a/host.h +++ b/host.h @@ -54,7 +54,6 @@ typedef struct host_static_s extern host_static_t host; void Host_Main(void); -void Host_Shutdown(void); void Host_Error(const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN; void Host_LockSession(void); void Host_UnlockSession(void); diff --git a/sys.h b/sys.h index baa7146b..26c71b50 100644 --- a/sys.h +++ b/sys.h @@ -217,7 +217,6 @@ void Sys_Printf(const char *fmt, ...); /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion void Sys_SDL_Shutdown(void); -void Sys_Quit (int returnvalue); /*! on some build/platform combinations (such as Linux gcc with the -pg * profiling option) this can turn on/off profiling, used primarily to limit diff --git a/sys_shared.c b/sys_shared.c index 6b5eef43..fde91ce3 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -60,33 +60,6 @@ char *Sys_TimeString(const char *timeformat) } -void Sys_Quit (int returnvalue) -{ - // Unlock mutexes because the quit command may jump directly here, causing a deadlock - if ((cmd_local)->cbuf->lock) - Cbuf_Unlock((cmd_local)->cbuf); - SV_UnlockThreadMutex(); - TaskQueue_Frame(true); - - if (Sys_CheckParm("-profilegameonly")) - Sys_AllowProfiling(false); - host.state = host_shutdown; - Host_Shutdown(); - -#ifdef __ANDROID__ - Sys_AllowProfiling(false); -#endif - -#ifndef WIN32 - fcntl(fileno(stdout), F_SETFL, fcntl(fileno(stdout), F_GETFL, 0) & ~O_NONBLOCK); - fcntl(fileno(stderr), F_SETFL, fcntl(fileno(stderr), F_GETFL, 0) & ~O_NONBLOCK); -#endif - fflush(stdout); - fflush(stderr); - - exit(returnvalue); -} - #ifdef __cplusplus extern "C" #endif @@ -1103,7 +1076,16 @@ int main (int argc, char **argv) Host_Main(); - Sys_Quit(0); +#ifdef __ANDROID__ + Sys_AllowProfiling(false); +#endif + +#ifndef WIN32 + fcntl(fileno(stdout), F_SETFL, fcntl(fileno(stdout), F_GETFL, 0) & ~O_NONBLOCK); + fcntl(fileno(stderr), F_SETFL, fcntl(fileno(stderr), F_GETFL, 0) & ~O_NONBLOCK); +#endif + fflush(stdout); + fflush(stderr); return 0; } -- 2.39.2