]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cmd: Use reentrant mutex for cbufs. Fixes deadlock when expanding aliases in some...
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 18 Jul 2020 19:45:09 +0000 (19:45 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 18 Jul 2020 19:45:09 +0000 (19:45 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12839 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
cmd.h
sys_shared.c

diff --git a/cmd.c b/cmd.c
index b7baf77eb78c42112ffe1e100e4277db76ccfce1..6e2b64791e7ac6f735521107c67e2227486a391a 100644 (file)
--- 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 40b7195884f9a3cb465f6e14a59f808979e11856..9016c27c65ba16bda0c352956c1341effdd6d958 100644 (file)
--- 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];
index 6b3f8c5a5a8b1b93340b92b86b0fb20b5b243c79..4898c82a02a1b0e8ea1315f1853f87b13b94a2dc 100644 (file)
@@ -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);