From 209d70e6e614ee97534f57d510affe0ed6309d15 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 12 Sep 2011 13:36:38 -0400 Subject: [PATCH] Clean up the win32 compiler warnings for SDL threads, in the 1.3 branch. --- include/SDL_thread.h | 12 -------- src/thread/windows/SDL_systhread.c | 45 +++++++++++++++++++----------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/include/SDL_thread.h b/include/SDL_thread.h index c771a3997..238ed3d43 100644 --- a/include/SDL_thread.h +++ b/include/SDL_thread.h @@ -90,17 +90,6 @@ typedef int (SDLCALL * SDL_ThreadFunction) (void *data); #include /* This has _beginthread() and _endthread() defined! */ #endif -#ifdef __GNUC__ -typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned - (__stdcall * - func) (void *), - void *arg, - unsigned, - unsigned - *threadID); -typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); -#else typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, unsigned (__stdcall * func) (void @@ -108,7 +97,6 @@ typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, void *arg, unsigned, unsigned *threadID); typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); -#endif /** * Create a thread. diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index d907c130c..a1a5a597a 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -33,16 +33,13 @@ #include #endif -#if __GNUC__ -typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, - unsigned - (__stdcall * - func) (void *), - void *arg, - unsigned, - unsigned - *threadID); -typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); +/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */ +#if (defined(__MINGW32__) && (__GNUC__ < 4)) +typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, + unsigned (__stdcall *func)(void *), void *arg, + unsigned, unsigned *threadID); +typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); + #elif defined(__WATCOMC__) /* This is for Watcom targets except OS2 */ #if __WATCOMC__ < 1240 @@ -59,6 +56,7 @@ typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *, unsigned *threadID); typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code); + #else typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, unsigned (__stdcall * @@ -77,7 +75,7 @@ typedef struct ThreadStartParms pfnSDL_CurrentEndThread pfnCurrentEndThread; } tThreadStartParms, *pThreadStartParms; -static unsigned __stdcall +static DWORD RunThread(void *data) { pThreadStartParms pThreadParms = (pThreadStartParms) data; @@ -97,6 +95,18 @@ RunThread(void *data) return (0); } +static DWORD WINAPI +RunThreadViaCreateThread(LPVOID data) +{ + return RunThread(data); +} + +static unsigned __stdcall +RunThreadViaBeginThreadEx(void *data) +{ + return (unsigned) RunThread(data); +} + #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD int SDL_SYS_CreateThread(SDL_Thread * thread, void *args, @@ -115,7 +125,6 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pfnSDL_CurrentEndThread pfnEndThread = _endthreadex; #endif #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ - DWORD threadid = 0; pThreadStartParms pThreadParms = (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms)); if (!pThreadParms) { @@ -128,12 +137,14 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args) pThreadParms->args = args; if (pfnBeginThread) { - thread->handle = - (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread, - pThreadParms, 0, &threadid); + unsigned threadid = 0; + thread->handle = (SYS_ThreadHandle) + ((size_t) pfnBeginThread(NULL, 0, RunThreadViaBeginThreadEx, + pThreadParms, 0, &threadid)); } else { - thread->handle = - CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid); + DWORD threadid = 0; + thread->handle = CreateThread(NULL, 0, RunThreadViaCreateThread, + pThreadParms, 0, &threadid); } if (thread->handle == NULL) { SDL_SetError("Not enough resources to create thread");