From e7e06d05f15b9444ff716e0268428373523eef6f Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 16 Jan 2023 03:22:01 +0100 Subject: [PATCH] Fix SDL1.2 build and type of xthreadInfo::threadId --- neo/sys/sys_public.h | 2 +- neo/sys/threads.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index bc985836..d84ae8a9 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -308,7 +308,7 @@ typedef int (*xthread_t)( void * ); typedef struct { const char *name; SDL_Thread *threadHandle; - unsigned int threadId; + unsigned long threadId; } xthreadInfo; void Sys_CreateThread( xthread_t function, void *parms, xthreadInfo &info, const char *name ); diff --git a/neo/sys/threads.cpp b/neo/sys/threads.cpp index 0c1f0e87..0b1132ae 100644 --- a/neo/sys/threads.cpp +++ b/neo/sys/threads.cpp @@ -36,6 +36,18 @@ If you have questions concerning this license or the applicable additional terms #include "sys/sys_public.h" +#if SDL_MAJOR_VERSION < 2 + // SDL1.2 doesn't have SDL_threadID but uses Uint32. + // this typedef helps using the same code for SDL1.2 and SDL2 + typedef Uint32 SDL_threadID; +#endif + +#if __cplusplus >= 201103 + // xthreadinfo::threadId doesn't use SDL_threadID directly so we don't drag SDL headers into sys_public.h + // but we should still make sure that the type fits (in SDL1.2 it's Uint32, in SDL2 it's unsigned long) + static_assert( sizeof(SDL_threadID) <= sizeof(xthreadInfo::threadId), "xthreadInfo::threadId has unsuitable type!" ); +#endif + static SDL_mutex *mutex[MAX_CRITICAL_SECTIONS] = { }; static SDL_cond *cond[MAX_TRIGGER_EVENTS] = { }; static bool signaled[MAX_TRIGGER_EVENTS] = { }; @@ -298,7 +310,7 @@ const char *Sys_GetThreadName(int *index) { Sys_EnterCriticalSection(); - unsigned int id = SDL_ThreadID(); + SDL_threadID id = SDL_ThreadID(); for (int i = 0; i < thread_count; i++) { if (id == thread[i]->threadId) {