mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-25 22:01:33 +00:00
[util] Make sys globals all thread-local
This was mainly for the shutdown functions, thus allowing Sys_Shutdown (and Sys_RegisterShutdown) to be per-thread, but it seemed like a good idea to make everything per-thread.
This commit is contained in:
parent
795021e229
commit
f9e442d323
2 changed files with 34 additions and 32 deletions
|
@ -138,8 +138,8 @@ static cvar_t sys_sleep_cvar = {
|
||||||
|
|
||||||
int sys_checksum;
|
int sys_checksum;
|
||||||
|
|
||||||
static sys_printf_t sys_std_printf_function = Sys_StdPrintf;
|
static __thread sys_printf_t sys_std_printf_function = Sys_StdPrintf;
|
||||||
static sys_printf_t sys_err_printf_function = Sys_ErrPrintf;
|
static __thread sys_printf_t sys_err_printf_function = Sys_ErrPrintf;
|
||||||
|
|
||||||
typedef struct shutdown_list_s {
|
typedef struct shutdown_list_s {
|
||||||
struct shutdown_list_s *next;
|
struct shutdown_list_s *next;
|
||||||
|
@ -153,10 +153,10 @@ typedef struct error_handler_s {
|
||||||
void *data;
|
void *data;
|
||||||
} error_handler_t;
|
} error_handler_t;
|
||||||
|
|
||||||
static shutdown_list_t *shutdown_list;
|
static __thread shutdown_list_t *shutdown_list;
|
||||||
|
|
||||||
static error_handler_t *error_handler_freelist;
|
static __thread error_handler_t *error_handler_freelist;
|
||||||
static error_handler_t *error_handler;
|
static __thread error_handler_t *error_handler;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static int do_stdin = 1;
|
static int do_stdin = 1;
|
||||||
|
@ -301,26 +301,26 @@ Sys_SetErrPrintf (sys_printf_t func)
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __thread dstring_t *sys_print_msg;
|
||||||
void
|
void
|
||||||
Sys_Print (FILE *stream, const char *fmt, va_list args)
|
Sys_Print (FILE *stream, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
static dstring_t *msg;
|
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
|
|
||||||
if (!msg)
|
if (!sys_print_msg)
|
||||||
msg = dstring_new ();
|
sys_print_msg = dstring_new ();
|
||||||
|
|
||||||
dvsprintf (msg, fmt, args);
|
dvsprintf (sys_print_msg, fmt, args);
|
||||||
|
|
||||||
if (stream == stderr) {
|
if (stream == stderr) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
MessageBox (NULL, msg->str, "Fatal Error", 0 /* MB_OK */ );
|
MessageBox (NULL, sys_print_msg->str, "Fatal Error", 0 /* MB_OK */ );
|
||||||
#endif
|
#endif
|
||||||
fputs ("Fatal Error: ", stream);
|
fputs ("Fatal Error: ", stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* translate to ASCII instead of printing [xx] --KB */
|
/* translate to ASCII instead of printing [xx] --KB */
|
||||||
for (p = (unsigned char *) msg->str; *p; p++)
|
for (p = (unsigned char *) sys_print_msg->str; *p; p++)
|
||||||
putc (sys_char_map[*p], stream);
|
putc (sys_char_map[*p], stream);
|
||||||
|
|
||||||
if (stream == stderr) {
|
if (stream == stderr) {
|
||||||
|
@ -795,21 +795,22 @@ Sys_ProcessorCount (void)
|
||||||
return cpus;
|
return cpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __thread dstring_t *sys_debuglog_data;
|
||||||
VISIBLE void
|
VISIBLE void
|
||||||
Sys_DebugLog (const char *file, const char *fmt, ...)
|
Sys_DebugLog (const char *file, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
static dstring_t *data;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!data)
|
if (!sys_debuglog_data)
|
||||||
data = dstring_newstr ();
|
sys_debuglog_data = dstring_newstr ();
|
||||||
|
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
dvsprintf (data, fmt, args);
|
dvsprintf (sys_debuglog_data, fmt, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
if ((fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) {
|
if ((fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) {
|
||||||
if (write (fd, data->str, data->size - 1) != (ssize_t) (data->size - 1))
|
if (write (fd, sys_debuglog_data->str, sys_debuglog_data->size - 1)
|
||||||
|
!= (ssize_t) (sys_debuglog_data->size - 1))
|
||||||
Sys_Printf ("Error writing %s: %s\n", file, strerror(errno));
|
Sys_Printf ("Error writing %s: %s\n", file, strerror(errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
|
@ -948,9 +949,9 @@ Sys_ConsoleInput (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static jmp_buf aiee_abort;
|
static __thread jmp_buf aiee_abort;
|
||||||
#else
|
#else
|
||||||
static sigjmp_buf aiee_abort;
|
static __thread sigjmp_buf aiee_abort;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct sh_stack_s {
|
typedef struct sh_stack_s {
|
||||||
|
@ -959,10 +960,10 @@ typedef struct sh_stack_s {
|
||||||
void *data;
|
void *data;
|
||||||
} sh_stack_t;
|
} sh_stack_t;
|
||||||
|
|
||||||
static sh_stack_t *sh_stack;
|
static __thread sh_stack_t *sh_stack;
|
||||||
static sh_stack_t *free_sh;
|
static __thread sh_stack_t *free_sh;
|
||||||
static int (*signal_hook)(int,void*);
|
static __thread int (*signal_hook)(int,void*);
|
||||||
static void *signal_hook_data;
|
static __thread void *signal_hook_data;
|
||||||
|
|
||||||
VISIBLE void
|
VISIBLE void
|
||||||
Sys_PushSignalHook (int (*hook)(int, void *), void *data)
|
Sys_PushSignalHook (int (*hook)(int, void *), void *data)
|
||||||
|
@ -1057,16 +1058,16 @@ hook_signlas (void)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static struct sigaction save_hup;
|
static __thread struct sigaction save_hup;
|
||||||
static struct sigaction save_quit;
|
static __thread struct sigaction save_quit;
|
||||||
static struct sigaction save_trap;
|
static __thread struct sigaction save_trap;
|
||||||
static struct sigaction save_iot;
|
static __thread struct sigaction save_iot;
|
||||||
static struct sigaction save_bus;
|
static __thread struct sigaction save_bus;
|
||||||
static struct sigaction save_int;
|
static __thread struct sigaction save_int;
|
||||||
static struct sigaction save_ill;
|
static __thread struct sigaction save_ill;
|
||||||
static struct sigaction save_segv;
|
static __thread struct sigaction save_segv;
|
||||||
static struct sigaction save_term;
|
static __thread struct sigaction save_term;
|
||||||
static struct sigaction save_fpe;
|
static __thread struct sigaction save_fpe;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
signal_handler (int sig, siginfo_t *info, void *ucontext)
|
signal_handler (int sig, siginfo_t *info, void *ucontext)
|
||||||
|
|
|
@ -323,6 +323,7 @@ run_progs (void *data)
|
||||||
thread->pr = 0;
|
thread->pr = 0;
|
||||||
Hash_DelContext (thread->hashctx);
|
Hash_DelContext (thread->hashctx);
|
||||||
thread->hashctx = 0;
|
thread->hashctx = 0;
|
||||||
|
Sys_Shutdown ();
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue