src/thread/SDL_thread.c
changeset 10145 cd87106d1d47
parent 9998 f67cf37e9cd4
child 10146 471eb08040ce
     1.1 --- a/src/thread/SDL_thread.c	Mon Apr 11 00:22:39 2016 -0400
     1.2 +++ b/src/thread/SDL_thread.c	Tue Apr 12 14:38:50 2016 -0400
     1.3 @@ -26,6 +26,7 @@
     1.4  #include "SDL_thread.h"
     1.5  #include "SDL_thread_c.h"
     1.6  #include "SDL_systhread.h"
     1.7 +#include "SDL_hints.h"
     1.8  #include "../SDL_error_c.h"
     1.9  
    1.10  
    1.11 @@ -304,15 +305,15 @@
    1.12  #endif
    1.13  
    1.14  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.15 -DECLSPEC SDL_Thread *SDLCALL
    1.16 -SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.17 -                 const char *name, void *data,
    1.18 +static SDL_Thread *
    1.19 +SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
    1.20 +                 const char *name, const size_t stacksize, void *data,
    1.21                   pfnSDL_CurrentBeginThread pfnBeginThread,
    1.22                   pfnSDL_CurrentEndThread pfnEndThread)
    1.23  #else
    1.24 -DECLSPEC SDL_Thread *SDLCALL
    1.25 -SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.26 -                 const char *name, void *data)
    1.27 +static SDL_Thread *
    1.28 +SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
    1.29 +                const char *name, const size_t stacksize, void *data)
    1.30  #endif
    1.31  {
    1.32      SDL_Thread *thread;
    1.33 @@ -362,6 +363,8 @@
    1.34          return (NULL);
    1.35      }
    1.36  
    1.37 +    thread->stacksize = stacksize;
    1.38 +
    1.39      /* Create the thread and go! */
    1.40  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.41      ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
    1.42 @@ -386,6 +389,40 @@
    1.43      return (thread);
    1.44  }
    1.45  
    1.46 +#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.47 +DECLSPEC SDL_Thread *SDLCALL
    1.48 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.49 +                 const char *name, void *data,
    1.50 +                 pfnSDL_CurrentBeginThread pfnBeginThread,
    1.51 +                 pfnSDL_CurrentEndThread pfnEndThread)
    1.52 +#else
    1.53 +DECLSPEC SDL_Thread *SDLCALL
    1.54 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    1.55 +                 const char *name, void *data)
    1.56 +#endif
    1.57 +{
    1.58 +    /* !!! FIXME: in 2.1, just make stackhint part of the usual API. */
    1.59 +    const char *stackhint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE);
    1.60 +    size_t stacksize = 0;
    1.61 +
    1.62 +    /* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */
    1.63 +    if (stackhint != NULL) {
    1.64 +        char *endp = NULL;
    1.65 +        const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10);
    1.66 +        if ((*stackhint != '\0') && (*endp == '\0')) {  /* a valid number? */
    1.67 +            if (hintval > 0) {  /* reject bogus values. */
    1.68 +                stacksize = (size_t) hintval;
    1.69 +            }
    1.70 +        }
    1.71 +    }
    1.72 +
    1.73 +#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    1.74 +    return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, pfnBeginThread, pfnEndThread);
    1.75 +#else
    1.76 +    return SDL_CreateThreadWithStackSize(fn, name, stacksize, data);
    1.77 +#endif
    1.78 +}
    1.79 +
    1.80  SDL_threadID
    1.81  SDL_GetThreadID(SDL_Thread * thread)
    1.82  {