SDL
2.0
|
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_atomic.h"
#include "SDL_mutex.h"
#include "begin_code.h"
#include "close_code.h"
Go to the source code of this file.
Typedefs | |
typedef unsigned long | SDL_threadID |
typedef unsigned int | SDL_TLSID |
typedef int(* | SDL_ThreadFunction) (void *data) |
Enumerations | |
enum | SDL_ThreadPriority { SDL_THREAD_PRIORITY_LOW, SDL_THREAD_PRIORITY_NORMAL, SDL_THREAD_PRIORITY_HIGH } |
Functions | |
SDL_Thread * | SDL_CreateThread (SDL_ThreadFunction fn, const char *name, void *data) |
const char * | SDL_GetThreadName (SDL_Thread *thread) |
SDL_threadID | SDL_ThreadID (void) |
SDL_threadID | SDL_GetThreadID (SDL_Thread *thread) |
int | SDL_SetThreadPriority (SDL_ThreadPriority priority) |
void | SDL_WaitThread (SDL_Thread *thread, int *status) |
void | SDL_DetachThread (SDL_Thread *thread) |
SDL_TLSID | SDL_TLSCreate (void) |
Create an identifier that is globally visible to all threads but refers to data that is thread-specific. More... | |
void * | SDL_TLSGet (SDL_TLSID id) |
Get the value associated with a thread local storage ID for the current thread. More... | |
int | 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. More... | |
Header for the SDL thread management routines.
Definition in file SDL_thread.h.
The function passed to SDL_CreateThread(). It is passed a void* user context parameter and returns an int.
Definition at line 69 of file SDL_thread.h.
typedef unsigned long SDL_threadID |
Definition at line 49 of file SDL_thread.h.
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) a int return int return int size_t return size_t return const wchar_t return const wchar_t size_t return const char size_t return const char size_t return char return char return const char int return int char int return long char int return Sint64 char int return const char return const char char int return const char char int return const char char return const char const char size_t return const char const char size_t return double return double return double return double return double return double return double int return float return const char const char return SDL_iconv_t const char size_t char size_t return Uint32 int int int Uint32 Uint32 Uint32 Uint32 return SDL_Surface SDL_Surface return SDL_RWops int return SDL_Surface int return SDL_Surface Uint32 return SDL_Surface Uint8 Uint8 Uint8 return SDL_Surface Uint8 return SDL_Surface SDL_BlendMode return SDL_Surface SDL_Rect SDL_Surface Uint32 Uint32 return SDL_Surface const SDL_Rect Uint32 return SDL_Surface const SDL_Rect SDL_Surface SDL_Rect return SDL_Surface const SDL_Rect SDL_Surface const SDL_Rect return SDL_Surface SDL_Rect SDL_Surface SDL_Rect return SDL_Thread return SDL_Thread return SDL_Thread int return SDL_TLSID |
Definition at line 52 of file SDL_thread.h.
enum SDL_ThreadPriority |
The SDL thread priority.
Enumerator | |
---|---|
SDL_THREAD_PRIORITY_LOW | |
SDL_THREAD_PRIORITY_NORMAL | |
SDL_THREAD_PRIORITY_HIGH |
Definition at line 59 of file SDL_thread.h.
SDL_Thread* SDL_CreateThread | ( | SDL_ThreadFunction | fn, |
const char * | name, | ||
void * | data | ||
) |
Create a thread.
Thread naming is a little complicated: Most systems have very small limits for the string length (Haiku has 32 bytes, Linux currently has 16, Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll have to see what happens with your system's debugger. The name should be UTF-8 (but using the naming limits of C identifiers is a better bet). There are no requirements for thread naming conventions, so long as the string is null-terminated UTF-8, but these guidelines are helpful in choosing a name:
http://stackoverflow.com/questions/149932/naming-conventions-for-threads
If a system imposes requirements, SDL will try to munge the string for it (truncate, etc), but the original string contents will be available from SDL_GetThreadName().
void SDL_DetachThread | ( | SDL_Thread * | thread | ) |
A thread may be "detached" to signify that it should not remain until another thread has called SDL_WaitThread() on it. Detaching a thread is useful for long-running threads that nothing needs to synchronize with or further manage. When a detached thread is done, it simply goes away.
There is no way to recover the return code of a detached thread. If you need this, don't detach the thread and instead use SDL_WaitThread().
Once a thread is detached, you should usually assume the SDL_Thread isn't safe to reference again, as it will become invalid immediately upon the detached thread's exit, instead of remaining until someone has called SDL_WaitThread() to finally clean it up. As such, don't detach the same thread more than once.
If a thread has already exited when passed to SDL_DetachThread(), it will stop waiting for a call to SDL_WaitThread() and clean up immediately. It is not safe to detach a thread that might be used with SDL_WaitThread().
You may not call SDL_WaitThread() on a thread that has been detached. Use either that function or this one, but not both, or behavior is undefined.
It is safe to pass NULL to this function; it is a no-op.
Definition at line 481 of file SDL_thread.c.
References NULL, SDL_assert, SDL_AtomicCAS, SDL_AtomicGet, SDL_SYS_DetachThread(), SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_CLEANED, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_ZOMBIE, SDL_WaitThread(), and SDL_Thread::state.
SDL_threadID SDL_GetThreadID | ( | SDL_Thread * | thread | ) |
Get the thread identifier for the specified thread.
Equivalent to SDL_ThreadID() if the specified thread is NULL.
Definition at line 437 of file SDL_thread.c.
References SDL_ThreadID, and SDL_Thread::threadid.
const char* SDL_GetThreadName | ( | SDL_Thread * | thread | ) |
Get the thread name, as it was specified in SDL_CreateThread(). This function returns a pointer to a UTF-8 string that names the specified thread, or NULL if it doesn't have a name. This is internal memory, not to be free()'d by the caller, and remains valid until the specified thread is cleaned up by SDL_WaitThread().
Definition at line 450 of file SDL_thread.c.
References SDL_Thread::name, and NULL.
int SDL_SetThreadPriority | ( | SDL_ThreadPriority | priority | ) |
Set the priority for the current thread
Definition at line 460 of file SDL_thread.c.
References SDL_SYS_SetThreadPriority().
SDL_threadID SDL_ThreadID | ( | void | ) |
Get the thread identifier for the current thread.
Definition at line 48 of file SDL_systhread.c.
Referenced by SDL_SYS_SetupThread().
Create an identifier that is globally visible to all threads but refers to data that is thread-specific.
Definition at line 34 of file SDL_thread.c.
References SDL_AtomicIncRef.
Referenced by SDL_GetErrBuf().
Get the value associated with a thread local storage ID for the current thread.
id | The thread local storage ID |
Definition at line 41 of file SDL_thread.c.
References SDL_TLSData::array, SDL_TLSData::data, SDL_TLSData::limit, NULL, and SDL_SYS_GetTLSData().
Referenced by SDL_GetErrBuf().
Set the value associated with a thread local storage ID for the current thread.
id | The thread local storage ID |
value | The value to associate with the ID for the current thread |
destructor | A function called when the thread exits, to free the value. |
Definition at line 53 of file SDL_thread.c.
References SDL_TLSData::array, SDL_TLSData::data, SDL_TLSData::destructor, i, SDL_TLSData::limit, NULL, SDL_const_cast, SDL_InvalidParamError, SDL_OutOfMemory, SDL_realloc, SDL_SYS_GetTLSData(), SDL_SYS_SetTLSData(), and TLS_ALLOC_CHUNKSIZE.
Referenced by SDL_GetErrBuf().
void SDL_WaitThread | ( | SDL_Thread * | thread, |
int * | status | ||
) |
Wait for a thread to finish. Threads that haven't been detached will remain (as a "zombie") until this function cleans them up. Not doing so is a resource leak.
Once a thread has been cleaned up through this function, the SDL_Thread that references it becomes invalid and should not be referenced again. As such, only one thread may call SDL_WaitThread() on another.
The return code for the thread function is placed in the area pointed to by status
, if status
is not NULL.
You may not wait on a thread that has been used in a call to SDL_DetachThread(). Use either that function or this one, but not both, or behavior is undefined.
It is safe to pass NULL to this function; it is a no-op.
Definition at line 466 of file SDL_thread.c.
References SDL_Thread::name, SDL_free, SDL_SYS_WaitThread(), and SDL_Thread::status.
Referenced by SDL_DetachThread().