From 16e01f9c31dc2d1179648ac3178f03f3b5d719cb Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Fri, 6 Jan 2023 21:39:36 +0300 Subject: [PATCH 1/3] Add fallback q_alignof() definition. --- inc/shared/platform.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inc/shared/platform.h b/inc/shared/platform.h index 9288aa0c4..29152446c 100644 --- a/inc/shared/platform.h +++ b/inc/shared/platform.h @@ -142,10 +142,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #define q_malloc #define q_sentinel -#define q_likely(x) !!(x) -#define q_unlikely(x) !!(x) +#define q_likely(x) (x) +#define q_unlikely(x) (x) #define q_offsetof(t, m) ((size_t)&((t *)0)->m) +#ifdef _MSC_VER #define q_alignof(t) __alignof(t) +#else +#define q_alignof(t) 1 +#endif #define q_gameabi From a6c847ac8892a1ec120ab1243a32101761a61a39 Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Sat, 14 Jan 2023 14:22:37 +0300 Subject: [PATCH 2/3] Change shouldExit/errorEntered to atomic types. --- inc/shared/atomic.h | 27 +++++++++++++++++++++++++++ src/client/http.c | 9 +-------- src/windows/system.c | 17 +++++++++-------- 3 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 inc/shared/atomic.h diff --git a/inc/shared/atomic.h b/inc/shared/atomic.h new file mode 100644 index 000000000..8385ef058 --- /dev/null +++ b/inc/shared/atomic.h @@ -0,0 +1,27 @@ +/* +Copyright (C) 2023 Andrey Nazarov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#ifdef _MSC_VER +typedef volatile int atomic_int; +#define atomic_load(p) (*(p)) +#define atomic_store(p, v) (*(p) = (v)) +#else +#include +#endif diff --git a/src/client/http.c b/src/client/http.c index ee799654c..882581605 100644 --- a/src/client/http.c +++ b/src/client/http.c @@ -21,14 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include -#ifdef _MSC_VER -typedef volatile int atomic_int; -#define atomic_load(p) (*(p)) -#define atomic_store(p, v) (*(p) = (v)) -#else -#include -#endif - +#include "shared/atomic.h" #include "system/pthread.h" static cvar_t *cl_http_downloads; diff --git a/src/windows/system.c b/src/windows/system.c index bfaf9ee45..8935e2719 100644 --- a/src/windows/system.c +++ b/src/windows/system.c @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/cvar.h" #include "common/field.h" #include "common/prompt.h" +#include "shared/atomic.h" #if USE_WINSVC #include @@ -33,8 +34,8 @@ static SERVICE_STATUS_HANDLE statusHandle; static jmp_buf exitBuf; #endif -static volatile BOOL shouldExit; -static volatile BOOL errorEntered; +static atomic_int shouldExit; +static atomic_int errorEntered; static LARGE_INTEGER timer_freq; @@ -593,10 +594,10 @@ void Sys_SetConsoleTitle(const char *title) static BOOL WINAPI Sys_ConsoleCtrlHandler(DWORD dwCtrlType) { - if (errorEntered) { + if (atomic_load(&errorEntered)) { exit(1); } - shouldExit = TRUE; + atomic_store(&shouldExit, TRUE); Sleep(INFINITE); return TRUE; } @@ -825,9 +826,9 @@ void Sys_Error(const char *error, ...) longjmp(exitBuf, 1); #endif - errorEntered = TRUE; + atomic_store(&errorEntered, TRUE); - if (shouldExit || (sys_exitonerror && sys_exitonerror->integer)) + if (atomic_load(&shouldExit) || (sys_exitonerror && sys_exitonerror->integer)) exit(1); #if USE_SYSCON @@ -1229,7 +1230,7 @@ static int Sys_Main(int argc, char **argv) Qcommon_Init(argc, argv); // main program loop - while (!shouldExit) + while (!atomic_load(&shouldExit)) Qcommon_Frame(); Com_Quit(NULL, ERR_DISCONNECT); @@ -1305,7 +1306,7 @@ static int sys_argc; static void WINAPI ServiceHandler(DWORD fdwControl) { if (fdwControl == SERVICE_CONTROL_STOP) { - shouldExit = TRUE; + atomic_store(&shouldExit, TRUE); } } From 2ec9a8a9cdf466bc1d2815b3441e010b8546af27 Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Mon, 9 Oct 2023 18:42:08 +0300 Subject: [PATCH 3/3] Remove Sys_ParseCommandLine(). Just use __argc/__argv directly. Fixes #313. --- src/windows/system.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/windows/system.c b/src/windows/system.c index 8935e2719..8288e4201 100644 --- a/src/windows/system.c +++ b/src/windows/system.c @@ -1239,43 +1239,6 @@ static int Sys_Main(int argc, char **argv) #if USE_CLIENT -#define MAX_LINE_TOKENS 128 - -static char *sys_argv[MAX_LINE_TOKENS]; -static int sys_argc; - -/* -=============== -Sys_ParseCommandLine - -=============== -*/ -static void Sys_ParseCommandLine(char *line) -{ - sys_argc = 1; - sys_argv[0] = APPLICATION; - while (*line) { - while (*line && *line <= 32) { - line++; - } - if (*line == 0) { - break; - } - sys_argv[sys_argc++] = line; - while (*line > 32) { - line++; - } - if (*line == 0) { - break; - } - *line = 0; - if (sys_argc == MAX_LINE_TOKENS) { - break; - } - line++; - } -} - /* ================== WinMain @@ -1291,9 +1254,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine hGlobalInstance = hInstance; - Sys_ParseCommandLine(lpCmdLine); - - return Sys_Main(sys_argc, sys_argv); + return Sys_Main(__argc, __argv); } #else // USE_CLIENT