SDL  2.0
SDL_thread_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_thread.h"
#include "generic/SDL_systhread_c.h"
#include "../SDL_error_c.h"
+ Include dependency graph for SDL_thread_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Thread
struct  SDL_TLSData

Macros

#define TLS_ALLOC_CHUNKSIZE   4

Enumerations

enum  SDL_ThreadState {
  SDL_THREAD_STATE_ALIVE,
  SDL_THREAD_STATE_DETACHED,
  SDL_THREAD_STATE_ZOMBIE,
  SDL_THREAD_STATE_CLEANED
}

Functions

void SDL_RunThread (void *data)
SDL_TLSDataSDL_Generic_GetTLSData (void)
int SDL_Generic_SetTLSData (SDL_TLSData *data)

Macro Definition Documentation

#define TLS_ALLOC_CHUNKSIZE   4

Definition at line 79 of file SDL_thread_c.h.

Referenced by SDL_TLSSet().

Enumeration Type Documentation

Enumerator:
SDL_THREAD_STATE_ALIVE 
SDL_THREAD_STATE_DETACHED 
SDL_THREAD_STATE_ZOMBIE 
SDL_THREAD_STATE_CLEANED 

Definition at line 45 of file SDL_thread_c.h.

Function Documentation

SDL_TLSData* SDL_Generic_GetTLSData ( void  )

Definition at line 124 of file SDL_thread.c.

References mutex, SDL_TLSEntry::next, NULL, SDL_AtomicLock, SDL_AtomicUnlock, SDL_CreateMutex, SDL_LockMutex, SDL_MemoryBarrierAcquire, SDL_MemoryBarrierRelease, SDL_ThreadID, SDL_UnlockMutex, SDL_TLSEntry::storage, and SDL_TLSEntry::thread.

Referenced by SDL_SYS_GetTLSData().

{
SDL_TLSEntry *entry;
SDL_TLSData *storage = NULL;
#if !SDL_THREADS_DISABLED
static SDL_SpinLock tls_lock;
SDL_AtomicLock(&tls_lock);
SDL_AtomicUnlock(&tls_lock);
return NULL;
}
}
SDL_AtomicUnlock(&tls_lock);
}
#endif /* SDL_THREADS_DISABLED */
for (entry = SDL_generic_TLS; entry; entry = entry->next) {
if (entry->thread == thread) {
storage = entry->storage;
break;
}
}
#if !SDL_THREADS_DISABLED
#endif
return storage;
}
int SDL_Generic_SetTLSData ( SDL_TLSData data)

Definition at line 163 of file SDL_thread.c.

References SDL_TLSEntry::next, NULL, SDL_free, SDL_generic_TLS, SDL_LockMutex, SDL_malloc, SDL_OutOfMemory, SDL_ThreadID, SDL_UnlockMutex, SDL_TLSEntry::storage, and SDL_TLSEntry::thread.

Referenced by SDL_SYS_SetTLSData().

{
SDL_TLSEntry *prev, *entry;
/* SDL_Generic_GetTLSData() is always called first, so we can assume SDL_generic_TLS_mutex */
prev = NULL;
for (entry = SDL_generic_TLS; entry; entry = entry->next) {
if (entry->thread == thread) {
if (storage) {
entry->storage = storage;
} else {
if (prev) {
prev->next = entry->next;
} else {
}
SDL_free(entry);
}
break;
}
prev = entry;
}
if (!entry) {
entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry));
if (entry) {
entry->thread = thread;
entry->storage = storage;
SDL_generic_TLS = entry;
}
}
if (!entry) {
return SDL_OutOfMemory();
}
return 0;
}
void SDL_RunThread ( void data)

Definition at line 265 of file SDL_thread.c.

References thread_args::data, thread_args::func, thread_args::info, SDL_AtomicCAS, SDL_free, SDL_SemPost, SDL_SYS_SetupThread(), SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_CLEANED, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_ZOMBIE, SDL_ThreadID, SDL_TLSCleanup(), SDLCALL, SDL_TLSEntry::thread, and thread_args::wait.

Referenced by RunThread().

{
int (SDLCALL * userfunc) (void *) = args->func;
void *userdata = args->data;
SDL_Thread *thread = args->info;
int *statusloc = &thread->status;
/* Perform any system-dependent setup - this function may not fail */
SDL_SYS_SetupThread(thread->name);
/* Get the thread id */
thread->threadid = SDL_ThreadID();
/* Wake up the parent thread */
SDL_SemPost(args->wait);
/* Run the function */
*statusloc = userfunc(userdata);
/* Clean up thread-local storage */
/* Mark us as ready to be joined (or detached) */
/* Clean up if something already detached us. */
if (thread->name) {
SDL_free(thread->name);
}
SDL_free(thread);
}
}
}