From: cloudwalk Date: Sat, 18 Jul 2020 19:45:09 +0000 (+0000) Subject: cmd: Use reentrant mutex for cbufs. Fixes deadlock when expanding aliases in some... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4620b4e54cd32935a3b477c1da74b09ce704734f;p=xonotic%2Fdarkplaces.git cmd: Use reentrant mutex for cbufs. Fixes deadlock when expanding aliases in some situations git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12839 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cmd.c b/cmd.c index b7baf77e..6e2b6479 100644 --- a/cmd.c +++ b/cmd.c @@ -49,12 +49,12 @@ qboolean host_stuffcmdsrun = false; void Cbuf_Lock(cmd_state_t *cmd) { - Thread_AtomicLock(&cmd->text_lock); + Thread_LockMutex(cmd->text_mutex); } void Cbuf_Unlock(cmd_state_t *cmd) { - Thread_AtomicUnlock(&cmd->text_lock); + Thread_UnlockMutex(cmd->text_mutex); } @@ -1512,16 +1512,19 @@ void Cmd_Init(void) cmd_client.cvars_flagsmask = CVAR_CLIENT | CVAR_SERVER; cmd_client.cmd_flags = CMD_CLIENT | CMD_CLIENT_FROM_SERVER | CMD_SERVER_FROM_CLIENT; cmd_client.userdefined = &cmd_userdefined_all; + cmd_client.text_mutex = Thread_CreateMutex(); // dedicated server console can only see server cvars, there is no client cmd_server.cvars = &cvars_all; cmd_server.cvars_flagsmask = CVAR_SERVER; cmd_server.cmd_flags = CMD_SERVER; cmd_server.userdefined = &cmd_userdefined_all; + cmd_server.text_mutex = Thread_CreateMutex(); // server commands received from clients have no reason to access cvars, cvar expansion seems perilous. cmd_serverfromclient.cvars = &cvars_null; cmd_serverfromclient.cvars_flagsmask = 0; cmd_serverfromclient.cmd_flags = CMD_SERVER_FROM_CLIENT | CMD_USERINFO; cmd_serverfromclient.userdefined = &cmd_userdefined_null; + cmd_serverfromclient.text_mutex = Thread_CreateMutex(); // // register our commands @@ -1576,7 +1579,7 @@ void Cmd_Shutdown(void) { cmd_state_t *cmd = cmd_iter->cmd; - if (cmd->text_lock) + if (cmd->text_mutex) { // we usually have this locked when we get here from Host_Quit_f Cbuf_Unlock(cmd); diff --git a/cmd.h b/cmd.h index 40b71958..9016c27c 100644 --- a/cmd.h +++ b/cmd.h @@ -114,7 +114,7 @@ typedef struct cmd_state_s sizebuf_t text; unsigned char text_buf[CMDBUFSIZE]; - Thread_SpinLock text_lock; + void *text_mutex; int argc; const char *argv[MAX_ARGS]; diff --git a/sys_shared.c b/sys_shared.c index 6b3f8c5a..4898c82a 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -48,9 +48,9 @@ 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_client.text_lock) + if (cmd_client.text_mutex) Cbuf_Unlock(&cmd_client); - if (cmd_server.text_lock) + if (cmd_server.text_mutex) Cbuf_Unlock(&cmd_server); SV_UnlockThreadMutex(); TaskQueue_Frame(true);