zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_thread.h File Reference
#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 struct SDL_Thread SDL_Thread
 
typedef unsigned long SDL_threadID
 
typedef unsigned int SDL_TLSID
 

Enumerations

enum  SDL_ThreadPriority { SDL_THREAD_PRIORITY_LOW, SDL_THREAD_PRIORITY_NORMAL, SDL_THREAD_PRIORITY_HIGH }
 

Functions

typedef int (SDLCALL *SDL_ThreadFunction)(void *data)
 
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread (SDL_ThreadFunction fn, const char *name, void *data)
 
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID (SDL_Thread *thread)
 
DECLSPEC const char *SDLCALL SDL_GetThreadName (SDL_Thread *thread)
 
DECLSPEC int SDLCALL SDL_SetThreadPriority (SDL_ThreadPriority priority)
 
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID (void)
 
DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate (void)
 Create an identifier that is globally visible to all threads but refers to data that is thread-specific. More...
 
DECLSPEC void *SDLCALL SDL_TLSGet (SDL_TLSID id)
 Get the value associated with a thread local storage ID for the current thread. More...
 
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. More...
 
DECLSPEC void SDLCALL SDL_WaitThread (SDL_Thread *thread, int *status)
 

Typedef Documentation

typedef struct SDL_Thread SDL_Thread

Definition at line 46 of file SDL_thread.h.

typedef unsigned long SDL_threadID

Definition at line 49 of file SDL_thread.h.

typedef unsigned int SDL_TLSID

Definition at line 52 of file SDL_thread.h.

Enumeration Type Documentation

The SDL thread priority.

Note
On many systems you require special privileges to set high priority.
Enumerator
SDL_THREAD_PRIORITY_LOW 
SDL_THREAD_PRIORITY_NORMAL 
SDL_THREAD_PRIORITY_HIGH 

Definition at line 59 of file SDL_thread.h.

Function Documentation

typedef int ( SDLCALL SDL_ThreadFunction)

The function passed to SDL_CreateThread(). It is passed a void* user context parameter and returns an int.

DECLSPEC SDL_Thread* SDLCALL 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 (BeOS 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().

Referenced by open_audio_device(), PSP_EventInit(), SDL_SYS_JoystickInit(), and SDL_TimerInit().

DECLSPEC SDL_threadID SDLCALL 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 370 of file SDL_thread.c.

References SDL_ThreadID(), and SDL_Thread::threadid.

DECLSPEC const char* SDLCALL 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 383 of file SDL_thread.c.

References SDL_Thread::name, and NULL.

DECLSPEC int SDLCALL SDL_SetThreadPriority ( SDL_ThreadPriority  priority)

Set the priority for the current thread

Definition at line 393 of file SDL_thread.c.

References SDL_SYS_SetThreadPriority().

Referenced by SDL_RunAudio().

DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate ( void  )

Create an identifier that is globally visible to all threads but refers to data that is thread-specific.

Returns
The newly created thread local storage identifier, or 0 on error
* static SDL_SpinLock tls_lock;
*
* void SetMyThreadData(void *value)
* {
* if (!thread_local_storage) {
* SDL_AtomicLock(&tls_lock);
* if (!thread_local_storage) {
* thread_local_storage = SDL_TLSCreate();
* }
* SDL_AtomicUnLock(&tls_lock);
* }
* SDL_TLSSet(thread_local_storage, value);
* }
*
* void *GetMyThreadData(void)
* {
* return SDL_TLSGet(thread_local_storage);
* }
*
See Also
SDL_TLSGet()
SDL_TLSSet()

Definition at line 32 of file SDL_thread.c.

References SDL_AtomicIncRef.

Referenced by SDL_GetErrBuf(), and SDL_VideoInit().

DECLSPEC void* SDLCALL SDL_TLSGet ( SDL_TLSID  id)

Get the value associated with a thread local storage ID for the current thread.

Parameters
idThe thread local storage ID
Returns
The value associated with the ID for the current thread, or NULL if no value has been set.
See Also
SDL_TLSCreate()
SDL_TLSSet()

Definition at line 39 of file SDL_thread.c.

References SDL_TLSData::array, SDL_TLSData::data, SDL_TLSData::limit, NULL, and SDL_SYS_GetTLSData().

Referenced by SDL_GetErrBuf(), SDL_GL_GetCurrentContext(), and SDL_GL_GetCurrentWindow().

DECLSPEC int SDLCALL SDL_TLSSet ( SDL_TLSID  id,
const void value,
void(*)(void *)  destructor 
)

Set the value associated with a thread local storage ID for the current thread.

Parameters
idThe thread local storage ID
valueThe value to associate with the ID for the current thread
destructorA function called when the thread exits, to free the value.
Returns
0 on success, -1 on error
See Also
SDL_TLSCreate()
SDL_TLSGet()

Definition at line 51 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(), SDL_GL_CreateContext(), and SDL_GL_MakeCurrent().

DECLSPEC void SDLCALL SDL_WaitThread ( SDL_Thread thread,
int status 
)

Wait for a thread to finish.

The return code for the thread function is placed in the area pointed to by status, if status is not NULL.

Definition at line 399 of file SDL_thread.c.

References SDL_Thread::name, SDL_free(), SDL_SYS_WaitThread(), and SDL_Thread::status.

Referenced by close_audio_device(), PSP_EventQuit(), SDL_SYS_JoystickQuit(), and SDL_TimerQuit().