Make it possible for the application to use different C runtime begin/end thread functions
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Feb 2020 08:26:46 -0800
changeset 13503eb6023298d0e
parent 13502 607750a641d7
child 13504 3d991f099f58
Make it possible for the application to use different C runtime begin/end thread functions
include/SDL_thread.h
     1.1 --- a/include/SDL_thread.h	Tue Feb 11 08:01:44 2020 -0800
     1.2 +++ b/include/SDL_thread.h	Tue Feb 11 08:26:46 2020 -0800
     1.3 @@ -93,11 +93,18 @@
     1.4  #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
     1.5  #include <process.h> /* _beginthreadex() and _endthreadex() */
     1.6  
     1.7 -typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)
     1.8 +typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread)
     1.9                     (void *, unsigned, unsigned (__stdcall *func)(void *),
    1.10                      void * /*arg*/, unsigned, unsigned * /* threadID */);
    1.11  typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
    1.12  
    1.13 +#ifndef SDL_beginthread
    1.14 +#define SDL_beginthread _beginthreadex
    1.15 +#endif
    1.16 +#ifndef SDL_endthread
    1.17 +#define SDL_endthread _endthreadex
    1.18 +#endif
    1.19 +
    1.20  /**
    1.21   *  Create a thread.
    1.22   */
    1.23 @@ -118,12 +125,12 @@
    1.24   */
    1.25  #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
    1.26  #undef SDL_CreateThread
    1.27 -#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    1.28 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.29  #undef SDL_CreateThreadWithStackSize
    1.30 -#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    1.31 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.32  #else
    1.33 -#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    1.34 -#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    1.35 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.36 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.37  #endif
    1.38  
    1.39  #elif defined(__OS2__)
    1.40 @@ -132,13 +139,23 @@
    1.41   * into a dll with Watcom's runtime statically linked.
    1.42   */
    1.43  #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.44 +
    1.45  #ifndef __EMX__
    1.46  #include <process.h>
    1.47  #else
    1.48  #include <stdlib.h>
    1.49  #endif
    1.50 +
    1.51  typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
    1.52  typedef void (*pfnSDL_CurrentEndThread)(void);
    1.53 +
    1.54 +#ifndef SDL_beginthread
    1.55 +#define SDL_beginthread _beginthread
    1.56 +#endif
    1.57 +#ifndef SDL_endthread
    1.58 +#define SDL_endthread _endthread
    1.59 +#endif
    1.60 +
    1.61  extern DECLSPEC SDL_Thread *SDLCALL
    1.62  SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
    1.63                   pfnSDL_CurrentBeginThread pfnBeginThread,
    1.64 @@ -147,14 +164,15 @@
    1.65  SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
    1.66                   pfnSDL_CurrentBeginThread pfnBeginThread,
    1.67                   pfnSDL_CurrentEndThread pfnEndThread);
    1.68 +
    1.69  #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
    1.70  #undef SDL_CreateThread
    1.71 -#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    1.72 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.73  #undef SDL_CreateThreadWithStackSize
    1.74 -#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    1.75 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.76  #else
    1.77 -#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    1.78 -#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    1.79 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.80 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
    1.81  #endif
    1.82  
    1.83  #else