thread: make SDL_CreateThreadWithStackSize() a public API.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 11 Oct 2018 16:40:01 -0400
changeset 12317d147224c0f28
parent 12316 e9954c42ee01
child 12318 69ebb2ebced0
thread: make SDL_CreateThreadWithStackSize() a public API.
include/SDL_hints.h
include/SDL_thread.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/thread/SDL_thread.c
     1.1 --- a/include/SDL_hints.h	Tue Oct 09 23:01:43 2018 -0700
     1.2 +++ b/include/SDL_hints.h	Thu Oct 11 16:40:01 2018 -0400
     1.3 @@ -619,6 +619,10 @@
     1.4  *  This is specially useful if you build SDL against a non glibc libc library (such as musl) which
     1.5  *  provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses).
     1.6  *  Support for this hint is currently available only in the pthread, Windows, and PSP backend.
     1.7 +*
     1.8 +*  Instead of this hint, in 2.0.9 and later, you can use
     1.9 +*  SDL_CreateThreadWithStackSize(). This hint only works with the classic
    1.10 +*  SDL_CreateThread().
    1.11  */
    1.12  #define SDL_HINT_THREAD_STACK_SIZE              "SDL_THREAD_STACK_SIZE"
    1.13  
     2.1 --- a/include/SDL_thread.h	Tue Oct 09 23:01:43 2018 -0700
     2.2 +++ b/include/SDL_thread.h	Thu Oct 11 16:40:01 2018 -0400
     2.3 @@ -106,14 +106,23 @@
     2.4                   pfnSDL_CurrentBeginThread pfnBeginThread,
     2.5                   pfnSDL_CurrentEndThread pfnEndThread);
     2.6  
     2.7 +extern DECLSPEC SDL_Thread *SDLCALL
     2.8 +SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
     2.9 +                 const char *name, const size_t stacksize, void *data,
    2.10 +                 pfnSDL_CurrentBeginThread pfnBeginThread,
    2.11 +                 pfnSDL_CurrentEndThread pfnEndThread);
    2.12 +
    2.13 +
    2.14  /**
    2.15   *  Create a thread.
    2.16   */
    2.17  #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
    2.18  #undef SDL_CreateThread
    2.19  #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    2.20 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    2.21  #else
    2.22  #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    2.23 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
    2.24  #endif
    2.25  
    2.26  #elif defined(__OS2__)
    2.27 @@ -133,16 +142,31 @@
    2.28  SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
    2.29                   pfnSDL_CurrentBeginThread pfnBeginThread,
    2.30                   pfnSDL_CurrentEndThread pfnEndThread);
    2.31 +extern DECLSPEC SDL_Thread *SDLCALL
    2.32 +SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data,
    2.33 +                 pfnSDL_CurrentBeginThread pfnBeginThread,
    2.34 +                 pfnSDL_CurrentEndThread pfnEndThread);
    2.35  #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
    2.36  #undef SDL_CreateThread
    2.37  #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    2.38 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    2.39  #else
    2.40  #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    2.41 +#define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
    2.42  #endif
    2.43  
    2.44  #else
    2.45  
    2.46  /**
    2.47 + *  Create a thread with a default stack size.
    2.48 + *
    2.49 + *  This is equivalent to calling:
    2.50 + *  SDL_CreateThreadWithStackSize(fn, name, 0, data);
    2.51 + */
    2.52 +extern DECLSPEC SDL_Thread *SDLCALL
    2.53 +SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
    2.54 +
    2.55 +/**
    2.56   *  Create a thread.
    2.57   *
    2.58   *   Thread naming is a little complicated: Most systems have very small
    2.59 @@ -159,9 +183,17 @@
    2.60   *   If a system imposes requirements, SDL will try to munge the string for
    2.61   *    it (truncate, etc), but the original string contents will be available
    2.62   *    from SDL_GetThreadName().
    2.63 + *
    2.64 + *   The size (in bytes) of the new stack can be specified. Zero means "use
    2.65 + *    the system default" which might be wildly different between platforms
    2.66 + *    (x86 Linux generally defaults to eight megabytes, an embedded device
    2.67 + *    might be a few kilobytes instead).
    2.68 + *
    2.69 + *   In SDL 2.1, stacksize will be folded into the original SDL_CreateThread
    2.70 + *    function.
    2.71   */
    2.72  extern DECLSPEC SDL_Thread *SDLCALL
    2.73 -SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
    2.74 +SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
    2.75  
    2.76  #endif
    2.77  
     3.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Tue Oct 09 23:01:43 2018 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Thu Oct 11 16:40:01 2018 -0400
     3.3 @@ -697,3 +697,4 @@
     3.4  #define SDL_IsTablet SDL_IsTablet_REAL
     3.5  #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
     3.6  #define SDL_HasColorKey SDL_HasColorKey_REAL
     3.7 +#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
     4.1 --- a/src/dynapi/SDL_dynapi_procs.h	Tue Oct 09 23:01:43 2018 -0700
     4.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Thu Oct 11 16:40:01 2018 -0400
     4.3 @@ -739,3 +739,16 @@
     4.4  SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return)
     4.5  SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return)
     4.6  SDL_DYNAPI_PROC(SDL_bool,SDL_HasColorKey,(SDL_Surface *a),(a),return)
     4.7 +
     4.8 +#ifdef SDL_CreateThreadWithStackSize
     4.9 +#undef SDL_CreateThreadWithStackSize
    4.10 +#endif
    4.11 +
    4.12 +#if defined(__WIN32__) && !defined(HAVE_LIBC)
    4.13 +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, pfnSDL_CurrentBeginThread e, pfnSDL_CurrentEndThread f),(a,b,c,d,e,f),return)
    4.14 +#elif defined(__OS2__)
    4.15 +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d, pfnSDL_CurrentBeginThread e, pfnSDL_CurrentEndThread f),(a,b,c,d,e,f),return)
    4.16 +#else
    4.17 +SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return)
    4.18 +#endif
    4.19 +
     5.1 --- a/src/thread/SDL_thread.c	Tue Oct 09 23:01:43 2018 -0700
     5.2 +++ b/src/thread/SDL_thread.c	Thu Oct 11 16:40:01 2018 -0400
     5.3 @@ -299,19 +299,21 @@
     5.4  
     5.5  #ifdef SDL_CreateThread
     5.6  #undef SDL_CreateThread
     5.7 +#undef SDL_CreateThreadWithStackSize
     5.8  #endif
     5.9  #if SDL_DYNAMIC_API
    5.10  #define SDL_CreateThread SDL_CreateThread_REAL
    5.11 +#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
    5.12  #endif
    5.13  
    5.14  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    5.15 -static SDL_Thread *
    5.16 +SDL_Thread *
    5.17  SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
    5.18                   const char *name, const size_t stacksize, void *data,
    5.19                   pfnSDL_CurrentBeginThread pfnBeginThread,
    5.20                   pfnSDL_CurrentEndThread pfnEndThread)
    5.21  #else
    5.22 -static SDL_Thread *
    5.23 +SDL_Thread *
    5.24  SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
    5.25                  const char *name, const size_t stacksize, void *data)
    5.26  #endif