25 #include "SDL_thread.h"
28 #include "../SDL_error_c.h"
44 if (!storage ||
id == 0 ||
id > storage->
limit) {
60 if (!storage || (
id > storage->
limit)) {
61 unsigned int i, oldlimit, newlimit;
63 oldlimit = storage ? storage->
limit : 0;
69 storage->
limit = newlimit;
70 for (i = oldlimit; i < newlimit; ++
i) {
92 for (i = 0; i < storage->
limit; ++
i) {
128 #if !SDL_THREADS_DISABLED
129 if (!SDL_generic_TLS_mutex) {
132 if (!SDL_generic_TLS_mutex) {
135 SDL_generic_TLS_mutex = mutex;
136 if (!SDL_generic_TLS_mutex) {
147 for (entry = SDL_generic_TLS; entry; entry = entry->next) {
148 if (entry->thread == thread) {
149 storage = entry->storage;
153 #if !SDL_THREADS_DISABLED
169 for (entry = SDL_generic_TLS; entry; entry = entry->next) {
170 if (entry->thread == thread) {
172 entry->storage = storage;
175 prev->next = entry->next;
177 SDL_generic_TLS = entry->next;
189 entry->storage = storage;
191 SDL_generic_TLS = entry;
217 if (!tls_errbuf && !tls_being_created) {
230 return &SDL_global_errbuf;
235 if (errbuf == ALLOCATION_IN_PROGRESS) {
236 return &SDL_global_errbuf;
244 return &SDL_global_errbuf;
265 thread_args *args = (thread_args *) data;
266 int (
SDLCALL * userfunc) (
void *) = args->func;
267 void *userdata = args->data;
268 int *statusloc = &args->info->status;
280 *statusloc = userfunc(userdata);
286 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
287 #undef SDL_CreateThread
291 pfnSDL_CurrentBeginThread pfnBeginThread,
292 pfnSDL_CurrentEndThread pfnEndThread)
296 const char *name,
void *data)
305 if (thread ==
NULL) {
323 args = (thread_args *)
SDL_malloc(
sizeof(*args));
336 if (args->wait ==
NULL) {
346 #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
static SDL_mutex * SDL_generic_TLS_mutex
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock)
Unlock a spin lock by setting it to 0. Always returns immediately.
unsigned long SDL_threadID
struct SDL_semaphore SDL_sem
SDL_TLSData * SDL_Generic_GetTLSData()
#define SDL_MemoryBarrierRelease()
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread *thread)
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread)
#define TLS_ALLOC_CHUNKSIZE
DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex *mutex)
int SDL_Generic_SetTLSData(SDL_TLSData *storage)
DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void)
DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size)
DECLSPEC void SDLCALL SDL_free(void *mem)
DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void)
Create an identifier that is globally visible to all threads but refers to data that is thread-specif...
EGLImageKHR EGLint * name
int SDL_SYS_SetTLSData(SDL_TLSData *data)
#define SDL_InvalidParamError(param)
#define SDL_const_cast(type, expression)
SDL_TLSData * SDL_SYS_GetTLSData()
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
SDL_error * SDL_GetErrBuf(void)
#define SDL_MemoryBarrierAcquire()
DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex *mutex)
void(* destructor)(void *)
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
void SDL_SYS_WaitThread(SDL_Thread *thread)
DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock)
Lock a spin lock by setting it to a non-zero value.
struct SDL_TLSEntry SDL_TLSEntry
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
static void SDL_TLSCleanup()
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
static SDL_Thread * thread
#define SDL_OutOfMemory()
struct SDL_mutex SDL_mutex
EGLSurface EGLint void ** value
static SDL_TLSEntry * SDL_generic_TLS
DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void(*destructor)(void *))
Set the value associated with a thread local storage ID for the current thread.
void SDL_RunThread(void *data)
void SDL_SYS_SetupThread(const char *name)
DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority)
DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)
struct SDL_TLSData::@84 array[1]
DECLSPEC void *SDLCALL SDL_TLSGet(SDL_TLSID id)
Get the value associated with a thread local storage ID for the current thread.