| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | #include "SDL_thread.h" |
| | | #include "SDL_thread_c.h" |
| | | #include "SDL_systhread.h" |
| | | #include "SDL_hints.h" |
| | | #include "../SDL_error_c.h" |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | int |
| | | SDL_TLSSet(SDL_TLSID id, const void *value, void (*destructor)(void *)) |
| | | SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *)) |
| | | { |
| | | SDL_TLSData *storage; |
| | | |
| | |
| | | |
| | | |
| | | SDL_TLSData * |
| | | SDL_Generic_GetTLSData() |
| | | SDL_Generic_GetTLSData(void) |
| | | { |
| | | SDL_threadID thread = SDL_ThreadID(); |
| | | SDL_TLSEntry *entry; |
| | |
| | | |
| | | #ifdef SDL_CreateThread |
| | | #undef SDL_CreateThread |
| | | #undef SDL_CreateThreadWithStackSize |
| | | #endif |
| | | #if SDL_DYNAMIC_API |
| | | #define SDL_CreateThread SDL_CreateThread_REAL |
| | | #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL |
| | | #endif |
| | | |
| | | #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD |
| | | DECLSPEC SDL_Thread *SDLCALL |
| | | SDL_CreateThread(int (SDLCALL * fn) (void *), |
| | | const char *name, void *data, |
| | | SDL_Thread * |
| | | SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), |
| | | const char *name, const size_t stacksize, void *data, |
| | | pfnSDL_CurrentBeginThread pfnBeginThread, |
| | | pfnSDL_CurrentEndThread pfnEndThread) |
| | | #else |
| | | DECLSPEC SDL_Thread *SDLCALL |
| | | SDL_CreateThread(int (SDLCALL * fn) (void *), |
| | | const char *name, void *data) |
| | | SDL_Thread * |
| | | SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), |
| | | const char *name, const size_t stacksize, void *data) |
| | | #endif |
| | | { |
| | | SDL_Thread *thread; |
| | |
| | | return (NULL); |
| | | } |
| | | |
| | | thread->stacksize = stacksize; |
| | | |
| | | /* Create the thread and go! */ |
| | | #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD |
| | | ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread); |
| | |
| | | return (thread); |
| | | } |
| | | |
| | | #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD |
| | | DECLSPEC SDL_Thread *SDLCALL |
| | | SDL_CreateThread(int (SDLCALL * fn) (void *), |
| | | const char *name, void *data, |
| | | pfnSDL_CurrentBeginThread pfnBeginThread, |
| | | pfnSDL_CurrentEndThread pfnEndThread) |
| | | #else |
| | | DECLSPEC SDL_Thread *SDLCALL |
| | | SDL_CreateThread(int (SDLCALL * fn) (void *), |
| | | const char *name, void *data) |
| | | #endif |
| | | { |
| | | /* !!! FIXME: in 2.1, just make stackhint part of the usual API. */ |
| | | const char *stackhint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE); |
| | | size_t stacksize = 0; |
| | | |
| | | /* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */ |
| | | if (stackhint != NULL) { |
| | | char *endp = NULL; |
| | | const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10); |
| | | if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */ |
| | | if (hintval > 0) { /* reject bogus values. */ |
| | | stacksize = (size_t) hintval; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD |
| | | return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, pfnBeginThread, pfnEndThread); |
| | | #else |
| | | return SDL_CreateThreadWithStackSize(fn, name, stacksize, data); |
| | | #endif |
| | | } |
| | | |
| | | SDL_Thread * |
| | | SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name, |
| | | const size_t stacksize, void *data) { |
| | | #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD |
| | | return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL); |
| | | #else |
| | | return SDL_CreateThreadWithStackSize(fn, name, stacksize, data); |
| | | #endif |
| | | } |
| | | |
| | | SDL_threadID |
| | | SDL_GetThreadID(SDL_Thread * thread) |
| | | { |