SDL
2.0
|
Go to the source code of this file.
Macros | |
#define | SDL_MUTEX_TIMEDOUT 1 |
#define | SDL_MUTEX_MAXWAIT (~(Uint32)0) |
Mutex functions | |
#define | SDL_mutexP(m) SDL_LockMutex(m) |
#define | SDL_mutexV(m) SDL_UnlockMutex(m) |
typedef struct SDL_mutex | SDL_mutex |
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) |
Semaphore functions | |
typedef struct SDL_semaphore | SDL_sem |
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 | |
typedef struct SDL_cond | SDL_cond |
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) |
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.
#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.
#define SDL_mutexP | ( | m | ) | SDL_LockMutex(m) |
Definition at line 100 of file SDL_mutex.h.
#define SDL_mutexV | ( | m | ) | SDL_UnlockMutex(m) |
Definition at line 142 of file SDL_mutex.h.
Definition at line 323 of file SDL_mutex.h.
Definition at line 1 of file SDL_mutex.h.
typedef struct SDL_semaphore SDL_sem |
Definition at line 162 of file SDL_mutex.h.
int SDL_CondBroadcast | ( | SDL_cond * | cond | ) |
Restart all threads that are waiting on the condition variable.
cond | the condition variable to signal |
int SDL_CondSignal | ( | SDL_cond * | cond | ) |
Restart one of the threads that are waiting on the condition variable.
cond | the condition variable to signal |
Wait until a condition variable is signaled.
This function unlocks the specified mutex
and waits for another thread to call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable cond
. Once the condition variable is signaled, the mutex is re-locked and the function returns.
The mutex must be locked before calling this function.
This function is the equivalent of calling SDL_CondWaitTimeout() with a time length of SDL_MUTEX_MAXWAIT
.
cond | the condition variable to wait on |
mutex | the mutex used to coordinate thread access |
Wait until a condition variable is signaled or a certain time has passed.
This function unlocks the specified mutex
and waits for another thread to call SDL_CondSignal() or SDL_CondBroadcast() on the condition variable cond
, or for the specified time to elapse. Once the condition variable is signaled or the time elapsed, the mutex is re-locked and the function returns.
The mutex must be locked before calling this function.
cond | the condition variable to wait on |
mutex | the mutex used to coordinate thread access |
ms | the maximum time to wait, in milliseconds, or SDL_MUTEX_MAXWAIT to wait indefinitely |
SDL_MUTEX_TIMEDOUT
if the condition is not signaled in the allotted time, or a negative error code on failure; call SDL_GetError() for more information.SDL_cond* SDL_CreateCond | ( | void | ) |
Create a condition variable.
SDL_mutex* SDL_CreateMutex | ( | void | ) |
Create a new mutex.
All newly-created mutexes begin in the unlocked state.
Calls to SDL_LockMutex() will not return while the mutex is locked by another thread. See SDL_TryLockMutex() to attempt to lock without blocking.
SDL mutexes are reentrant.
Create a semaphore.
This function creates a new semaphore and initializes it with the value initial_value
. Each wait operation on the semaphore will atomically decrement the semaphore value and potentially block if the semaphore value is 0. Each post operation will atomically increment the semaphore value and wake waiting threads and allow them to retry the wait operation.
initial_value | the starting value of the semaphore |
void SDL_DestroyCond | ( | SDL_cond * | cond | ) |
Destroy a condition variable.
cond | the condition variable to destroy |
void SDL_DestroyMutex | ( | SDL_mutex * | mutex | ) |
Destroy a mutex created with SDL_CreateMutex().
This function must be called on any mutex that is no longer needed. Failure to destroy a mutex will result in a system memory or resource leak. While it is safe to destroy a mutex that is unlocked, it is not safe to attempt to destroy a locked mutex, and may result in undefined behavior depending on the platform.
mutex | the mutex to destroy |
void SDL_DestroySemaphore | ( | SDL_sem * | sem | ) |
Destroy a semaphore.
It is not safe to destroy a semaphore if there are threads currently waiting on it.
sem | the semaphore to destroy |
int SDL_LockMutex | ( | SDL_mutex * | mutex | ) |
Lock the mutex.
This will block until the mutex is available, which is to say it is in the unlocked state and the OS has chosen the caller as the next thread to lock it. Of all threads waiting to lock the mutex, only one may do so at a time.
It is legal for the owning thread to lock an already-locked mutex. It must unlock it the same number of times before it is actually made available for other threads in the system (this is known as a "recursive mutex").
mutex | the mutex to lock |
int SDL_SemPost | ( | SDL_sem * | sem | ) |
Atomically increment a semaphore's value and wake waiting threads.
sem | the semaphore to increment |
int SDL_SemTryWait | ( | SDL_sem * | sem | ) |
See if a semaphore has a positive value and decrement it if it does.
This function checks to see if the semaphore pointed to by sem
has a positive value and atomically decrements the semaphore value if it does. If the semaphore doesn't have a positive value, the function immediately returns SDL_MUTEX_TIMEDOUT.
sem | the semaphore to wait on |
SDL_MUTEX_TIMEDOUT
if the wait would block, or a negative error code on failure; call SDL_GetError() for more information.Get the current value of a semaphore.
sem | the semaphore to query |
int SDL_SemWait | ( | SDL_sem * | sem | ) |
Wait until a semaphore has a positive value and then decrements it.
This function suspends the calling thread until either the semaphore pointed to by sem
has a positive value or the call is interrupted by a signal or error. If the call is successful it will atomically decrement the semaphore value.
This function is the equivalent of calling SDL_SemWaitTimeout() with a time length of SDL_MUTEX_MAXWAIT
.
sem | the semaphore wait on |
Wait until a semaphore has a positive value and then decrements it.
This function suspends the calling thread until either the semaphore pointed to by sem
has a positive value, the call is interrupted by a signal or error, or the specified time has elapsed. If the call is successful it will atomically decrement the semaphore value.
sem | the semaphore to wait on |
ms | the length of the timeout, in milliseconds |
SDL_MUTEX_TIMEDOUT
if the wait does not succeed in the allotted time, or a negative error code on failure; call SDL_GetError() for more information.int SDL_TryLockMutex | ( | SDL_mutex * | mutex | ) |
Try to lock a mutex without blocking.
This works just like SDL_LockMutex(), but if the mutex is not available, this function returns SDL_MUTEX_TIMEOUT
immediately.
This technique is useful if you need exclusive access to a resource but don't want to wait for it, and will return to it to try again later.
mutex | the mutex to try to lock |
SDL_MUTEX_TIMEDOUT
, or -1 on error; call SDL_GetError() for more information.int SDL_UnlockMutex | ( | SDL_mutex * | mutex | ) |
Unlock the mutex.
It is legal for the owning thread to lock an already-locked mutex. It must unlock it the same number of times before it is actually made available for other threads in the system (this is known as a "recursive mutex").
It is an error to unlock a mutex that has not been locked by the current thread, and doing so results in undefined behavior.
It is also an error to unlock a mutex that isn't locked at all.
mutex | the mutex to unlock. |