]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sys: refactor the clean shutdown process
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 22 Jan 2024 21:58:45 +0000 (07:58 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sun, 28 Jan 2024 03:25:29 +0000 (13:25 +1000)
After all the other refactors finally we can clean this up.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
host.c
host.h
sys.h
sys_shared.c

diff --git a/host.c b/host.c
index bb1b83fcf82ea4c87d1cb3dbd401ff07ba8066df..a2c43d859e8b60b769370857e75b8a496cea7be1 100644 (file)
--- 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 78bd8083f5ffaacc1ed1d898505559688c6209d1..89ea1f11947ac0dd5038d5e432d19971d7b4b099 100644 (file)
--- 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 baa7146bc292a295dd8e9c38fee639afd021a8e1..26c71b5055196e7fe141ec9be05fe1397a3aafc3 100644 (file)
--- 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
index 6b5eef4343cce9360a15676626ca2671932fe173..fde91ce36d147a4cf68f511885d2ab85d23557d7 100644 (file)
@@ -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;
 }