[util] Pass a data pointer to shutdown functions

And clean up the mess.
This commit is contained in:
Bill Currie 2020-03-21 22:24:11 +09:00
parent 176cc7b9c1
commit 88b4046632
26 changed files with 56 additions and 54 deletions

View file

@ -469,7 +469,7 @@ SV_WriteFilterList (void)
}
static void
SV_Shutdown (void)
SV_Shutdown (void *data)
{
NET_Shutdown ();
@ -525,7 +525,7 @@ main (int argc, const char **argv)
mst_cbuf = Cbuf_New (&id_interp);
Sys_RegisterShutdown (SV_Shutdown);
Sys_RegisterShutdown (SV_Shutdown, 0);
Sys_Init ();

View file

@ -77,7 +77,7 @@ void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2), noret
void Sys_FatalError (const char *error, ...) __attribute__((format(printf,1,2), noreturn));
void Sys_Quit (void) __attribute__((noreturn));
void Sys_Shutdown (void);
void Sys_RegisterShutdown (void (*func) (void));
void Sys_RegisterShutdown (void (*func) (void *), void *data);
int64_t Sys_LongTime (void);
double Sys_DoubleTime (void);
void Sys_TimeOfDay(date_t *date);

View file

@ -70,7 +70,7 @@ void Log_Incoming_Packet (const byte *p, int len, int has_sequence,
int is_server);
void Log_Outgoing_Packet (const byte *p, int len, int has_sequence,
int is_server);
void Net_LogStop (void);
void Net_LogStop (void *data);
void Analyze_Client_Packet (const byte * data, int len, int has_sequence);
void Analyze_Server_Packet (const byte * data, int len, int has_sequence);

View file

@ -105,7 +105,8 @@ static sys_printf_t sys_err_printf_function = Sys_ErrPrintf;
typedef struct shutdown_list_s {
struct shutdown_list_s *next;
void (*func)(void);
void (*func) (void *);
void *data;
} shutdown_list_t;
typedef struct error_handler_s {
@ -492,7 +493,7 @@ Sys_Shutdown (void)
shutdown_list_t *t;
while (shutdown_list) {
shutdown_list->func ();
shutdown_list->func (shutdown_list->data);
t = shutdown_list;
shutdown_list = shutdown_list->next;
free (t);
@ -571,7 +572,7 @@ Sys_Error (const char *error, ...)
}
VISIBLE void
Sys_RegisterShutdown (void (*func) (void))
Sys_RegisterShutdown (void (*func) (void *), void *data)
{
shutdown_list_t *p;
if (!func)
@ -580,6 +581,7 @@ Sys_RegisterShutdown (void (*func) (void))
if (!p)
Sys_Error ("Sys_RegisterShutdown: insufficient memory");
p->func = func;
p->data = data;
p->next = shutdown_list;
shutdown_list = p;
}

View file

@ -61,7 +61,7 @@ void Host_ClearMemory (void);
void Host_ServerFrame (void);
void Host_InitCommands (void);
void Host_Init (void);
void Host_Shutdown(void);
void Host_Shutdown(void *data);
void Host_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn));
void Host_EndGame (const char *message, ...) __attribute__((format(printf,1,2), noreturn));
void Host_Frame (float time);

View file

@ -957,7 +957,7 @@ Host_Init (void)
better to run quit through here before final handoff to the sys code.
*/
void
Host_Shutdown (void)
Host_Shutdown (void *data)
{
static qboolean isdown = false;

View file

@ -85,7 +85,7 @@ startup (void)
}
static void
shutdown_f (void)
shutdown_f (void *data)
{
#ifndef _WIN32
// change stdin to blocking
@ -113,8 +113,8 @@ SDL_main (int argc, char *argv[])
isDedicated = (COM_CheckParm ("-dedicated") != 0);
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -55,7 +55,7 @@
qboolean isDedicated = false;
static void
shutdown_f (void)
shutdown_f (void *data)
{
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
@ -75,8 +75,8 @@ main (int argc, const char **argv)
isDedicated = (COM_CheckParm ("-dedicated") != 0);
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -53,7 +53,7 @@
qboolean isDedicated = true;
static void
shutdown_f (void)
shutdown_f (void *data)
{
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
@ -86,8 +86,8 @@ main (int argc, const char **argv)
host_parms.argc = com_argc;
host_parms.argv = com_argv;
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -104,7 +104,7 @@ startup (void)
}
static void
shutdown_f (void)
shutdown_f (void *data)
{
if (tevent)
CloseHandle (tevent);
@ -207,8 +207,8 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (!isDedicated)
init_handles (hInstance);
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -39,7 +39,7 @@
qboolean isDedicated = true;
static void
shutdown_f (void)
shutdown_f (void *data)
{
}
@ -69,8 +69,8 @@ main (int argc, const char **argv)
host_parms.argc = com_argc;
host_parms.argv = com_argv;
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -220,7 +220,7 @@ qtv_memory_init (void)
}
static void
qtv_shutdown (void)
qtv_shutdown (void *data)
{
NET_Shutdown ();
Con_Shutdown ();
@ -253,7 +253,7 @@ qtv_init (void)
qtv_cbuf = Cbuf_New (&id_interp);
qtv_args = Cbuf_ArgsNew ();
Sys_RegisterShutdown (qtv_shutdown);
Sys_RegisterShutdown (qtv_shutdown, 0);
Sys_Init ();
COM_ParseConfig ();

View file

@ -508,7 +508,7 @@ sv_list_f (void)
}
static void
server_shutdown (void)
server_shutdown (void *data)
{
Hash_FlushTable (server_hash);
Hash_DelTable (server_hash);
@ -540,7 +540,7 @@ server_run (server_t *sv)
void
Server_Init (void)
{
Sys_RegisterShutdown (server_shutdown);
Sys_RegisterShutdown (server_shutdown, 0);
server_hash = Hash_NewTable (61, server_get_key, server_free, 0);
Cmd_AddCommand ("sv_new", sv_new_f, "Add a new server");
Cmd_AddCommand ("sv_del", sv_del_f, "Remove an existing server");

View file

@ -50,7 +50,7 @@ extern int host_framecount; // incremented every frame, never reset
void Host_ServerFrame (void);
void Host_InitCommands (void);
void Host_Init (void);
void Host_Shutdown(void);
void Host_Shutdown(void *data);
void Host_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn));
void Host_EndGame (const char *message, ...) __attribute__((format(printf,1,2), noreturn));
void Host_Frame (float time);

View file

@ -488,7 +488,7 @@ client_t *SV_AllocClient (int spectator, int server);
void SV_SavePenaltyFilter (client_t *cl, filtertype_t type, double pentime);
double SV_RestorePenaltyFilter (client_t *cl, filtertype_t type);
void SV_Shutdown (void);
void SV_Shutdown (void *data);
void SV_Frame (float time);
void SV_FinalMessage (const char *message);
void SV_DropClient (client_t *drop);

View file

@ -1867,7 +1867,7 @@ Host_Init (void)
}
void
Host_Shutdown (void)
Host_Shutdown (void *data)
{
static qboolean isdown = false;

View file

@ -93,7 +93,7 @@ startup (void)
}
static void
shutdown_f (void)
shutdown_f (void *data)
{
#ifndef _WIN32
// change stdin to blocking
@ -122,9 +122,9 @@ SDL_main (int argc, char *argv[])
if (!COM_CheckParm ("-noconinput"))
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
#endif
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (Net_LogStop, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -52,7 +52,7 @@
#include "netchan.h"
static void
shutdown_f (void)
shutdown_f (void *data)
{
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
@ -73,9 +73,9 @@ main (int argc, const char **argv)
if (!COM_CheckParm ("-noconinput"))
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (Net_LogStop, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -93,7 +93,7 @@ startup (void)
}
static void
shutdown_f (void)
shutdown_f (void *data)
{
if (tevent)
CloseHandle (tevent);
@ -181,9 +181,9 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (!tevent)
Sys_Error ("Couldn't create event");
Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (shutdown_f);
Sys_RegisterShutdown (Host_Shutdown, 0);
Sys_RegisterShutdown (Net_LogStop, 0);
Sys_RegisterShutdown (shutdown_f, 0);
Host_Init ();

View file

@ -177,7 +177,7 @@ Net_LogStart (const char *fname)
}
void
Net_LogStop (void)
Net_LogStop (void *data)
{
if (Net_PacketLog)
Qclose (Net_PacketLog);
@ -954,7 +954,7 @@ Net_PacketLog_f (cvar_t *var)
if (var->int_val) {
Net_LogStart ("qfpacket.log");
} else {
Net_LogStop ();
Net_LogStop (0);
}
}

View file

@ -223,7 +223,7 @@ SV_Restart_f (void)
net_message->message->data);
}
Sys_Printf ("Shutting down: server restart, shell must relaunch server\n");
SV_Shutdown ();
SV_Shutdown (0);
// Error code 2 on exit, indication shell must restart the server
exit (2);
}

View file

@ -237,7 +237,7 @@ Master_Shutdown (void)
Quake calls this before calling Sys_Quit or Sys_Error
*/
void
SV_Shutdown (void)
SV_Shutdown (void *data)
{
Master_Shutdown ();
if (sv_fraglogfile) {
@ -2486,7 +2486,7 @@ SV_Init (void)
sv_cbuf = Cbuf_New (&id_interp);
sv_args = Cbuf_ArgsNew ();
Sys_RegisterShutdown (SV_Shutdown);
Sys_RegisterShutdown (SV_Shutdown, 0);
Sys_Init ();
GIB_Init (true);

View file

@ -122,7 +122,7 @@ main (int argc, const char **argv)
SV_Init ();
Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (Net_LogStop, 0);
// run one frame immediately for first heartbeat
SV_Frame (0.1);

View file

@ -93,7 +93,7 @@ main (int argc, const char **argv)
if (WinNT)
Cvar_Set (sys_sleep, "0");
Sys_RegisterShutdown (Net_LogStop);
Sys_RegisterShutdown (Net_LogStop, 0);
// run one frame immediately for first heartbeat
SV_Frame (0.1);

View file

@ -159,7 +159,7 @@ static builtin_t builtins[] = {
};
static void
bi_shutdown (void)
bi_shutdown (void *data)
{
S_Shutdown ();
IN_Shutdown ();
@ -177,7 +177,7 @@ BI_Init (progs_t *pr)
PI_Init ();
PI_RegisterPlugins (client_plugin_list);
Sys_RegisterShutdown (bi_shutdown);
Sys_RegisterShutdown (bi_shutdown, 0);
VID_Init_Cvars ();
IN_Init_Cvars ();

View file

@ -921,7 +921,7 @@ process_input (qwaq_resources_t *res)
static int need_endwin;
static void
bi_shutdown (void)
bi_shutdown (void *_pr)
{
if (need_endwin) {
write(1, MOUSE_MOVES_OFF, sizeof (MOUSE_MOVES_OFF) - 1);
@ -1950,7 +1950,7 @@ BI_Init (progs_t *pr)
PR_Resources_Register (pr, "qwaq", res, bi_qwaq_clear);
PR_RegisterBuiltins (pr, builtins);
Sys_RegisterShutdown (bi_shutdown);
Sys_RegisterShutdown (bi_shutdown, pr);
logfile = fopen ("qwaq-curses.log", "wt");
Sys_SetStdPrintf (qwaq_print);
}