Clean up the win32 compiler warnings for SDL threads, in the 1.3 branch.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 12 Sep 2011 13:36:38 -0400
changeset 5904a21d78fc998c
parent 5903 cd9129438fdf
child 5905 4fc2f7e2bb52
Clean up the win32 compiler warnings for SDL threads, in the 1.3 branch.
include/SDL_thread.h
src/thread/windows/SDL_systhread.c
     1.1 --- a/include/SDL_thread.h	Mon Sep 12 09:00:34 2011 -0700
     1.2 +++ b/include/SDL_thread.h	Mon Sep 12 13:36:38 2011 -0400
     1.3 @@ -90,17 +90,6 @@
     1.4  #include <process.h>            /* This has _beginthread() and _endthread() defined! */
     1.5  #endif
     1.6  
     1.7 -#ifdef __GNUC__
     1.8 -typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
     1.9 -                                                             unsigned
    1.10 -                                                             (__stdcall *
    1.11 -                                                              func) (void *),
    1.12 -                                                             void *arg,
    1.13 -                                                             unsigned,
    1.14 -                                                             unsigned
    1.15 -                                                             *threadID);
    1.16 -typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
    1.17 -#else
    1.18  typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
    1.19                                                          unsigned (__stdcall *
    1.20                                                                    func) (void
    1.21 @@ -108,7 +97,6 @@
    1.22                                                          void *arg, unsigned,
    1.23                                                          unsigned *threadID);
    1.24  typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
    1.25 -#endif
    1.26  
    1.27  /**
    1.28   *  Create a thread.
     2.1 --- a/src/thread/windows/SDL_systhread.c	Mon Sep 12 09:00:34 2011 -0700
     2.2 +++ b/src/thread/windows/SDL_systhread.c	Mon Sep 12 13:36:38 2011 -0400
     2.3 @@ -33,16 +33,13 @@
     2.4  #include <process.h>
     2.5  #endif
     2.6  
     2.7 -#if __GNUC__
     2.8 -typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
     2.9 -                                                             unsigned
    2.10 -                                                             (__stdcall *
    2.11 -                                                              func) (void *),
    2.12 -                                                             void *arg,
    2.13 -                                                             unsigned,
    2.14 -                                                             unsigned
    2.15 -                                                             *threadID);
    2.16 -typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
    2.17 +/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */
    2.18 +#if (defined(__MINGW32__) && (__GNUC__ < 4))
    2.19 +typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
    2.20 +        unsigned (__stdcall *func)(void *), void *arg, 
    2.21 +        unsigned, unsigned *threadID);
    2.22 +typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
    2.23 +
    2.24  #elif defined(__WATCOMC__)
    2.25  /* This is for Watcom targets except OS2 */
    2.26  #if __WATCOMC__ < 1240
    2.27 @@ -59,6 +56,7 @@
    2.28                                                                 unsigned
    2.29                                                                 *threadID);
    2.30  typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code);
    2.31 +
    2.32  #else
    2.33  typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
    2.34                                                          unsigned (__stdcall *
    2.35 @@ -77,7 +75,7 @@
    2.36      pfnSDL_CurrentEndThread pfnCurrentEndThread;
    2.37  } tThreadStartParms, *pThreadStartParms;
    2.38  
    2.39 -static unsigned __stdcall
    2.40 +static DWORD
    2.41  RunThread(void *data)
    2.42  {
    2.43      pThreadStartParms pThreadParms = (pThreadStartParms) data;
    2.44 @@ -97,6 +95,18 @@
    2.45      return (0);
    2.46  }
    2.47  
    2.48 +static DWORD WINAPI
    2.49 +RunThreadViaCreateThread(LPVOID data)
    2.50 +{
    2.51 +  return RunThread(data);
    2.52 +}
    2.53 +
    2.54 +static unsigned __stdcall
    2.55 +RunThreadViaBeginThreadEx(void *data)
    2.56 +{
    2.57 +  return (unsigned) RunThread(data);
    2.58 +}
    2.59 +
    2.60  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    2.61  int
    2.62  SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
    2.63 @@ -115,7 +125,6 @@
    2.64      pfnSDL_CurrentEndThread pfnEndThread = _endthreadex;
    2.65  #endif
    2.66  #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
    2.67 -    DWORD threadid = 0;
    2.68      pThreadStartParms pThreadParms =
    2.69          (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
    2.70      if (!pThreadParms) {
    2.71 @@ -128,12 +137,14 @@
    2.72      pThreadParms->args = args;
    2.73  
    2.74      if (pfnBeginThread) {
    2.75 -        thread->handle =
    2.76 -            (SYS_ThreadHandle) pfnBeginThread(NULL, 0, RunThread,
    2.77 -                                              pThreadParms, 0, &threadid);
    2.78 +        unsigned threadid = 0;
    2.79 +        thread->handle = (SYS_ThreadHandle)
    2.80 +            ((size_t) pfnBeginThread(NULL, 0, RunThreadViaBeginThreadEx,
    2.81 +                                     pThreadParms, 0, &threadid));
    2.82      } else {
    2.83 -        thread->handle =
    2.84 -            CreateThread(NULL, 0, RunThread, pThreadParms, 0, &threadid);
    2.85 +        DWORD threadid = 0;
    2.86 +        thread->handle = CreateThread(NULL, 0, RunThreadViaCreateThread,
    2.87 +                                      pThreadParms, 0, &threadid);
    2.88      }
    2.89      if (thread->handle == NULL) {
    2.90          SDL_SetError("Not enough resources to create thread");