My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Typedefs | Enumerations | Functions
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 const char *SDLCALL SDL_GetThreadName (SDL_Thread *thread)
 
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID (void)
 
DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID (SDL_Thread *thread)
 
DECLSPEC int SDLCALL SDL_SetThreadPriority (SDL_ThreadPriority priority)
 
DECLSPEC void SDLCALL SDL_WaitThread (SDL_Thread *thread, int *status)
 
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...
 

Detailed Description

Header for the SDL thread management routines.

Enumeration Type Documentation

The SDL thread priority.

Note
On many systems you require special privileges to set high priority.

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().

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.

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().

DECLSPEC int SDLCALL SDL_SetThreadPriority ( SDL_ThreadPriority  priority)

Set the priority for the current thread

DECLSPEC SDL_threadID SDLCALL SDL_ThreadID ( void  )

Get the thread identifier for the current thread.

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;
* static SDL_TLSID thread_local_storage;
*
* 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()
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()
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()
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.