SDL
2.0
|
Go to the source code of this file.
Macros | |
#define | SDL_MUTEX_TIMEDOUT 1 |
#define | SDL_MUTEX_MAXWAIT (~(Uint32)0) |
Functions | |
Semaphore functions | |
SDL_sem * | SDL_CreateSemaphore (Uint32 initial_value) |
void | SDL_DestroySemaphore (SDL_sem *sem) |
int | SDL_SemWait (SDL_sem *sem) |
int | SDL_SemTryWait (SDL_sem *sem) |
int | SDL_SemWaitTimeout (SDL_sem *sem, Uint32 ms) |
int | SDL_SemPost (SDL_sem *sem) |
Uint32 | SDL_SemValue (SDL_sem *sem) |
Condition variable functions | |
SDL_cond * | SDL_CreateCond (void) |
void | SDL_DestroyCond (SDL_cond *cond) |
int | SDL_CondSignal (SDL_cond *cond) |
int | SDL_CondBroadcast (SDL_cond *cond) |
int | SDL_CondWait (SDL_cond *cond, SDL_mutex *mutex) |
int | SDL_CondWaitTimeout (SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) |
Mutex functions | |
#define | SDL_mutexP(m) SDL_LockMutex(m) |
#define | SDL_mutexV(m) SDL_UnlockMutex(m) |
SDL_mutex * | SDL_CreateMutex (void) |
int | SDL_LockMutex (SDL_mutex *mutex) |
int | SDL_TryLockMutex (SDL_mutex *mutex) |
int | SDL_UnlockMutex (SDL_mutex *mutex) |
void | SDL_DestroyMutex (SDL_mutex *mutex) |
Functions to provide thread synchronization primitives.
Definition in file SDL_mutex.h.
#define SDL_MUTEX_MAXWAIT (~(Uint32)0) |
This is the timeout value which corresponds to never time out.
Definition at line 49 of file SDL_mutex.h.
Referenced by SDL_CondWait(), SDL_CondWaitTimeout(), SDL_SemWait(), SDL_SemWaitTimeout(), and SDL_TimerThread().
#define SDL_MUTEX_TIMEDOUT 1 |
Synchronization functions which can time out return this value if they time out.
Definition at line 44 of file SDL_mutex.h.
Referenced by SDL_CondWaitTimeout(), SDL_SemTryWait(), SDL_SemWaitTimeout(), SDL_TryLockMutex(), and TestWaitTimeout().
#define SDL_mutexP | ( | m | ) | SDL_LockMutex(m) |
#define SDL_mutexV | ( | m | ) | SDL_UnlockMutex(m) |
Unlock the mutex.
Definition at line 89 of file SDL_mutex.h.
int SDL_CondBroadcast | ( | SDL_cond * | cond | ) |
Restart all threads that are waiting on the condition variable.
Definition at line 106 of file SDL_syscond.c.
References SDL_cond::cond, SDL_cond::cpp_cond, i, SDL_cond::lock, retval, SDL_LockMutex, SDL_SemPost, SDL_SemWait, SDL_SetError, SDL_UnlockMutex, SDL_cond::signals, SDL_cond::wait_done, SDL_cond::wait_sem, and SDL_cond::waiting.
int SDL_CondSignal | ( | SDL_cond * | cond | ) |
Restart one of the threads that are waiting on the condition variable.
Definition at line 82 of file SDL_syscond.c.
References SDL_cond::cond, SDL_cond::cpp_cond, SDL_cond::lock, retval, SDL_LockMutex, SDL_SemPost, SDL_SemWait, SDL_SetError, SDL_UnlockMutex, SDL_cond::signals, SDL_cond::wait_done, SDL_cond::wait_sem, and SDL_cond::waiting.
Wait on the condition variable, unlocking the provided mutex.
The mutex is re-locked once the condition variable is signaled.
Definition at line 215 of file SDL_syscond.c.
References SDL_cond::cond, SDL_mutex::id, SDL_CondWaitTimeout(), SDL_MUTEX_MAXWAIT, and SDL_SetError.
Waits for at most ms
milliseconds, and returns 0 if the condition variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not signaled in the allotted time, and -1 on error.
Definition at line 160 of file SDL_syscond.c.
References SDL_cond::cond, SDL_cond::cpp_cond, SDL_mutex::cpp_mutex, SDL_mutex::id, SDL_cond::lock, NULL, retval, SDL_LockMutex, SDL_MUTEX_MAXWAIT, SDL_MUTEX_TIMEDOUT, SDL_SemPost, SDL_SemWait, SDL_SemWaitTimeout, SDL_SetError, SDL_UnlockMutex, SDL_cond::signals, SDL_cond::wait_done, SDL_cond::wait_sem, and SDL_cond::waiting.
Referenced by SDL_CondWait().
Create a condition variable.
Typical use of condition variables:
Thread A: SDL_LockMutex(lock); while ( ! condition ) { SDL_CondWait(cond, lock); } SDL_UnlockMutex(lock);
Thread B: SDL_LockMutex(lock); ... condition = true; ... SDL_CondSignal(cond); SDL_UnlockMutex(lock);
There is some discussion whether to signal the condition variable with the mutex locked or not. There is some potential performance benefit to unlocking first on some platforms, but there are some potential race conditions depending on how your code is structured.
In general it's safer to signal the condition variable while the mutex is locked.
Definition at line 42 of file SDL_syscond.c.
References SDL_cond::cond, SDL_cond::lock, NULL, SDL_CreateMutex, SDL_CreateSemaphore, SDL_DestroyCond(), SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_SetError, SDL_cond::signals, SDL_cond::wait_done, SDL_cond::wait_sem, and SDL_cond::waiting.
Create a mutex, initialized unlocked.
Definition at line 38 of file SDL_sysmutex.c.
References SDL_mutex::id, mutex, NULL, SDL_mutex::owner, SDL_mutex::recursive, SDL_calloc, SDL_CreateSemaphore, SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_SetError, and SDL_mutex::sem.
SDL_sem* SDL_CreateSemaphore | ( | Uint32 | initial_value | ) |
Create a semaphore, initialized with value, returns NULL on failure.
Definition at line 85 of file SDL_syssem.c.
References NULL, SDL_CreateCond, SDL_CreateMutex, SDL_DestroySemaphore(), SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_SetError, and SDL_sem::sem.
Destroy a condition variable.
Definition at line 64 of file SDL_syscond.c.
References SDL_cond::cond, SDL_cond::lock, SDL_DestroyMutex, SDL_DestroySemaphore, SDL_free, SDL_cond::wait_done, and SDL_cond::wait_sem.
Referenced by SDL_CreateCond().
Destroy a mutex.
Definition at line 61 of file SDL_sysmutex.c.
References SDL_mutex::id, mutex, SDL_DestroySemaphore, SDL_free, and SDL_mutex::sem.
void SDL_DestroySemaphore | ( | SDL_sem * | sem | ) |
Destroy a semaphore.
Definition at line 111 of file SDL_syssem.c.
References SDL_CondSignal, SDL_Delay, SDL_DestroyCond, SDL_DestroyMutex, SDL_free, SDL_LockMutex, and SDL_UnlockMutex.
Referenced by SDL_CreateSemaphore().
int SDL_LockMutex | ( | SDL_mutex * | mutex | ) |
Definition at line 73 of file SDL_sysmutex.c.
References SDL_mutex::id, NULL, SDL_mutex::owner, SDL_mutex::recursive, SDL_SemWait, SDL_SetError, SDL_ThreadID, and SDL_mutex::sem.
int SDL_SemPost | ( | SDL_sem * | sem | ) |
Atomically increases the semaphore's count (not blocking).
Definition at line 200 of file SDL_syssem.c.
References retval, SDL_CondSignal, SDL_LockMutex, SDL_SetError, and SDL_UnlockMutex.
int SDL_SemTryWait | ( | SDL_sem * | sem | ) |
Non-blocking variant of SDL_SemWait().
Definition at line 130 of file SDL_syssem.c.
References retval, SDL_LockMutex, SDL_MUTEX_TIMEDOUT, SDL_SetError, and SDL_UnlockMutex.
Referenced by SDL_SemWaitTimeout().
Uint32 SDL_SemValue | ( | SDL_sem * | sem | ) |
Returns the current count of the semaphore.
Definition at line 186 of file SDL_syssem.c.
References SDL_LockMutex, and SDL_UnlockMutex.
int SDL_SemWait | ( | SDL_sem * | sem | ) |
This function suspends the calling thread until the semaphore pointed to by sem
has a positive count. It then atomically decreases the semaphore count.
Definition at line 180 of file SDL_syssem.c.
References retval, SDL_MUTEX_MAXWAIT, SDL_SemWaitTimeout(), and SDL_SetError.
Referenced by SDL_SemWaitTimeout().
int SDL_SemWaitTimeout | ( | SDL_sem * | sem, |
Uint32 | ms | ||
) |
Variant of SDL_SemWait() with a timeout in milliseconds.
Definition at line 150 of file SDL_syssem.c.
References NULL, retval, SDL_CondWaitTimeout, SDL_Delay, SDL_GetTicks(), SDL_LockMutex, SDL_MUTEX_MAXWAIT, SDL_MUTEX_TIMEDOUT, SDL_SemTryWait(), SDL_SemWait(), SDL_SetError, SDL_TICKS_PASSED, and SDL_UnlockMutex.
Referenced by SDL_SemWait().
int SDL_TryLockMutex | ( | SDL_mutex * | mutex | ) |
Try to lock the mutex
Definition at line 103 of file SDL_sysmutex.c.
References SDL_mutex::cpp_mutex, SDL_mutex::id, NULL, SDL_mutex::owner, SDL_mutex::recursive, retval, SDL_MUTEX_TIMEDOUT, SDL_SemWait, SDL_SetError, SDL_ThreadID, and SDL_mutex::sem.
int SDL_UnlockMutex | ( | SDL_mutex * | mutex | ) |
Definition at line 159 of file SDL_sysmutex.c.
References SDL_mutex::id, NULL, SDL_mutex::owner, SDL_mutex::recursive, and SDL_SetError.