SDL 3.0
|
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_thread.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
Go to the source code of this file.
Data Structures | |
struct | SDL_InitState |
Thread-safe initialization state functions | |
enum | SDL_InitStatus { SDL_INIT_STATUS_UNINITIALIZED , SDL_INIT_STATUS_INITIALIZING , SDL_INIT_STATUS_INITIALIZED , SDL_INIT_STATUS_UNINITIALIZING } |
bool | SDL_ShouldInit (SDL_InitState *state) |
bool | SDL_ShouldQuit (SDL_InitState *state) |
void | SDL_SetInitialized (SDL_InitState *state, bool initialized) |
Mutex functions | |
typedef struct SDL_Mutex | SDL_Mutex |
bool | mutex |
SDL_Mutex * | SDL_CreateMutex (void) |
void | SDL_LockMutex (SDL_Mutex *mutex) SDL_ACQUIRE(mutex) |
bool | SDL_TryLockMutex (SDL_Mutex *mutex) SDL_TRY_ACQUIRE(0 |
void | SDL_UnlockMutex (SDL_Mutex *mutex) SDL_RELEASE(mutex) |
void | SDL_DestroyMutex (SDL_Mutex *mutex) |
Read/write lock functions | |
typedef struct SDL_RWLock | SDL_RWLock |
bool | rwlock |
SDL_RWLock * | SDL_CreateRWLock (void) |
void | SDL_LockRWLockForReading (SDL_RWLock *rwlock) SDL_ACQUIRE_SHARED(rwlock) |
void | SDL_LockRWLockForWriting (SDL_RWLock *rwlock) SDL_ACQUIRE(rwlock) |
bool | SDL_TryLockRWLockForReading (SDL_RWLock *rwlock) SDL_TRY_ACQUIRE_SHARED(0 |
bool | SDL_TryLockRWLockForWriting (SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(0 |
void | SDL_UnlockRWLock (SDL_RWLock *rwlock) SDL_RELEASE_GENERIC(rwlock) |
void | SDL_DestroyRWLock (SDL_RWLock *rwlock) |
Semaphore functions | |
typedef struct SDL_Semaphore | SDL_Semaphore |
SDL_Semaphore * | SDL_CreateSemaphore (Uint32 initial_value) |
void | SDL_DestroySemaphore (SDL_Semaphore *sem) |
void | SDL_WaitSemaphore (SDL_Semaphore *sem) |
bool | SDL_TryWaitSemaphore (SDL_Semaphore *sem) |
bool | SDL_WaitSemaphoreTimeout (SDL_Semaphore *sem, Sint32 timeoutMS) |
void | SDL_SignalSemaphore (SDL_Semaphore *sem) |
Uint32 | SDL_GetSemaphoreValue (SDL_Semaphore *sem) |
Condition variable functions | |
typedef struct SDL_Condition | SDL_Condition |
SDL_Condition * | SDL_CreateCondition (void) |
void | SDL_DestroyCondition (SDL_Condition *cond) |
void | SDL_SignalCondition (SDL_Condition *cond) |
void | SDL_BroadcastCondition (SDL_Condition *cond) |
void | SDL_WaitCondition (SDL_Condition *cond, SDL_Mutex *mutex) |
bool | SDL_WaitConditionTimeout (SDL_Condition *cond, SDL_Mutex *mutex, Sint32 timeoutMS) |
#define SDL_ACQUIRE | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 157 of file SDL_mutex.h.
#define SDL_ACQUIRE_SHARED | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 167 of file SDL_mutex.h.
#define SDL_ACQUIRED_AFTER | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 127 of file SDL_mutex.h.
#define SDL_ACQUIRED_BEFORE | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 117 of file SDL_mutex.h.
#define SDL_ASSERT_CAPABILITY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 237 of file SDL_mutex.h.
#define SDL_ASSERT_SHARED_CAPABILITY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 247 of file SDL_mutex.h.
#define SDL_CAPABILITY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 77 of file SDL_mutex.h.
#define SDL_EXCLUDES | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 227 of file SDL_mutex.h.
#define SDL_GUARDED_BY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 97 of file SDL_mutex.h.
#define SDL_NO_THREAD_SAFETY_ANALYSIS SDL_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 267 of file SDL_mutex.h.
#define SDL_PT_GUARDED_BY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 107 of file SDL_mutex.h.
#define SDL_RELEASE | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 177 of file SDL_mutex.h.
#define SDL_RELEASE_GENERIC | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 197 of file SDL_mutex.h.
#define SDL_RELEASE_SHARED | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 187 of file SDL_mutex.h.
#define SDL_REQUIRES | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 137 of file SDL_mutex.h.
#define SDL_REQUIRES_SHARED | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 147 of file SDL_mutex.h.
#define SDL_RETURN_CAPABILITY | ( | x | ) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 257 of file SDL_mutex.h.
#define SDL_SCOPED_CAPABILITY SDL_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 87 of file SDL_mutex.h.
#define SDL_THREAD_ANNOTATION_ATTRIBUTE__ | ( | x | ) | /* no-op */ |
SDL offers several thread synchronization primitives. This document can't cover the complicated topic of thread safety, but reading up on what each of these primitives are, why they are useful, and how to correctly use them is vital to writing correct and safe multithreaded programs.
SDL also offers a datatype, SDL_InitState, which can be used to make sure only one thread initializes/deinitializes some resource that several threads might try to use for the first time simultaneously.
Definition at line 67 of file SDL_mutex.h.
#define SDL_TRY_ACQUIRE | ( | x, | |
y | |||
) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(x, y)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 207 of file SDL_mutex.h.
#define SDL_TRY_ACQUIRE_SHARED | ( | x, | |
y | |||
) | SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(x, y)) |
Wrapper around Clang thread safety analysis annotations.
Please see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h
Definition at line 217 of file SDL_mutex.h.
typedef struct SDL_Condition SDL_Condition |
A means to block multiple threads until a condition is satisfied.
Condition variables, paired with an SDL_Mutex, let an app halt multiple threads until a condition has occurred, at which time the app can release one or all waiting threads.
Wikipedia has a thorough explanation of the concept:
https://en.wikipedia.org/wiki/Condition_variable
Definition at line 801 of file SDL_mutex.h.
A means to serialize access to a resource between threads.
Mutexes (short for "mutual exclusion") are a synchronization primitive that allows exactly one thread to proceed at a time.
Wikipedia has a thorough explanation of the concept:
https://en.wikipedia.org/wiki/Mutex
Definition at line 296 of file SDL_mutex.h.
typedef struct SDL_RWLock SDL_RWLock |
A mutex that allows read-only threads to run in parallel.
A rwlock is roughly the same concept as SDL_Mutex, but allows threads that request read-only access to all hold the lock at the same time. If a thread requests write access, it will block until all read-only threads have released the lock, and no one else can hold the thread (for reading or writing) at the same time as the writing thread.
This can be more efficient in cases where several threads need to access data frequently, but changes to that data are rare.
There are other rules that apply to rwlocks that don't apply to mutexes, about how threads are scheduled and when they can be recursively locked. These are documented in the other rwlock functions.
Definition at line 427 of file SDL_mutex.h.
typedef struct SDL_Semaphore SDL_Semaphore |
A means to manage access to a resource, by count, between threads.
Semaphores (specifically, "counting semaphores"), let X number of threads request access at the same time, each thread granted access decrementing a counter. When the counter reaches zero, future requests block until a prior thread releases their request, incrementing the counter again.
Wikipedia has a thorough explanation of the concept:
https://en.wikipedia.org/wiki/Semaphore_(programming)
Definition at line 658 of file SDL_mutex.h.
enum SDL_InitStatus |
The current status of an SDL_InitState structure.
Enumerator | |
---|---|
SDL_INIT_STATUS_UNINITIALIZED | |
SDL_INIT_STATUS_INITIALIZING | |
SDL_INIT_STATUS_INITIALIZED | |
SDL_INIT_STATUS_UNINITIALIZING |
Definition at line 931 of file SDL_mutex.h.
void SDL_BroadcastCondition | ( | SDL_Condition * | cond | ) |
Restart all threads that are waiting on the condition variable.
cond | the condition variable to signal. |
\threadsafety It is safe to call this function from any thread.
SDL_Condition * SDL_CreateCondition | ( | 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.
SDL_RWLock * SDL_CreateRWLock | ( | void | ) |
Create a new read/write lock.
A read/write lock is useful for situations where you have multiple threads trying to access a resource that is rarely updated. All threads requesting a read-only lock will be allowed to run in parallel; if a thread requests a write lock, it will be provided exclusive access. This makes it safe for multiple threads to use a resource at the same time if they promise not to change it, and when it has to be changed, the rwlock will serve as a gateway to make sure those changes can be made safely.
In the right situation, a rwlock can be more efficient than a mutex, which only lets a single thread proceed at a time, even if it won't be modifying the data.
All newly-created read/write locks begin in the unlocked state.
Calls to SDL_LockRWLockForReading() and SDL_LockRWLockForWriting will not return while the rwlock is locked for writing by another thread. See SDL_TryLockRWLockForReading() and SDL_TryLockRWLockForWriting() to attempt to lock without blocking.
SDL read/write locks are only recursive for read-only locks! They are not guaranteed to be fair, or provide access in a FIFO manner! They are not guaranteed to favor writers. You may not lock a rwlock for both read-only and write access at the same time from the same thread (so you can't promote your read-only lock to a write lock without unlocking first).
SDL_Semaphore * SDL_CreateSemaphore | ( | Uint32 | initial_value | ) |
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_DestroyCondition | ( | SDL_Condition * | 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_DestroyRWLock | ( | SDL_RWLock * | rwlock | ) |
Destroy a read/write lock created with SDL_CreateRWLock().
This function must be called on any read/write lock that is no longer needed. Failure to destroy a rwlock will result in a system memory or resource leak. While it is safe to destroy a rwlock that is unlocked, it is not safe to attempt to destroy a locked rwlock, and may result in undefined behavior depending on the platform.
rwlock | the rwlock to destroy. |
void SDL_DestroySemaphore | ( | SDL_Semaphore * | 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. |
Uint32 SDL_GetSemaphoreValue | ( | SDL_Semaphore * | sem | ) |
Get the current value of a semaphore.
sem | the semaphore to query. |
void 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").
This function does not fail; if mutex is NULL, it will return immediately having locked nothing. If the mutex is valid, this function will always block until it can lock the mutex, and return with it locked.
mutex | the mutex to lock. |
void SDL_LockRWLockForReading | ( | SDL_RWLock * | rwlock | ) |
Lock the read/write lock for read only operations.
This will block until the rwlock is available, which is to say it is not locked for writing by any other thread. Of all threads waiting to lock the rwlock, all may do so at the same time as long as they are requesting read-only access; if a thread wants to lock for writing, only one may do so at a time, and no other threads, read-only or not, may hold the lock at the same time.
It is legal for the owning thread to lock an already-locked rwlock for reading. 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 rwlock").
Note that locking for writing is not recursive (this is only available to read-only locks).
It is illegal to request a read-only lock from a thread that already holds the write lock. Doing so results in undefined behavior. Unlock the write lock before requesting a read-only lock. (But, of course, if you have the write lock, you don't need further locks to read in any case.)
This function does not fail; if rwlock is NULL, it will return immediately having locked nothing. If the rwlock is valid, this function will always block until it can lock the mutex, and return with it locked.
rwlock | the read/write lock to lock. |
void SDL_LockRWLockForWriting | ( | SDL_RWLock * | rwlock | ) |
Lock the read/write lock for write operations.
This will block until the rwlock is available, which is to say it is not locked for reading or writing by any other thread. Only one thread may hold the lock when it requests write access; all other threads, whether they also want to write or only want read-only access, must wait until the writer thread has released the lock.
It is illegal for the owning thread to lock an already-locked rwlock for writing (read-only may be locked recursively, writing can not). Doing so results in undefined behavior.
It is illegal to request a write lock from a thread that already holds a read-only lock. Doing so results in undefined behavior. Unlock the read-only lock before requesting a write lock.
This function does not fail; if rwlock is NULL, it will return immediately having locked nothing. If the rwlock is valid, this function will always block until it can lock the mutex, and return with it locked.
rwlock | the read/write lock to lock. |
void SDL_SetInitialized | ( | SDL_InitState * | state, |
bool | initialized | ||
) |
Finish an initialization state transition.
This function sets the status of the passed in state to SDL_INIT_STATUS_INITIALIZED
or SDL_INIT_STATUS_UNINITIALIZED
and allows any threads waiting for the status to proceed.
state | the initialization state to check. |
initialized | the new initialization state. |
\threadsafety It is safe to call this function from any thread.
bool SDL_ShouldInit | ( | SDL_InitState * | state | ) |
Return whether initialization should be done.
This function checks the passed in state and if initialization should be done, sets the status to SDL_INIT_STATUS_INITIALIZING
and returns true. If another thread is already modifying this state, it will wait until that's done before returning.
If this function returns true, the calling code must call SDL_SetInitialized() to complete the initialization.
state | the initialization state to check. |
\threadsafety It is safe to call this function from any thread.
bool SDL_ShouldQuit | ( | SDL_InitState * | state | ) |
Return whether cleanup should be done.
This function checks the passed in state and if cleanup should be done, sets the status to SDL_INIT_STATUS_UNINITIALIZING
and returns true.
If this function returns true, the calling code must call SDL_SetInitialized() to complete the cleanup.
state | the initialization state to check. |
\threadsafety It is safe to call this function from any thread.
void SDL_SignalCondition | ( | SDL_Condition * | cond | ) |
Restart one of the threads that are waiting on the condition variable.
cond | the condition variable to signal. |
\threadsafety It is safe to call this function from any thread.
void SDL_SignalSemaphore | ( | SDL_Semaphore * | sem | ) |
Atomically increment a semaphore's value and wake waiting threads.
sem | the semaphore to increment. |
Try to lock a mutex without blocking.
This works just like SDL_LockMutex(), but if the mutex is not available, this function returns false 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.
This function returns true if passed a NULL mutex.
mutex | the mutex to try to lock. |
bool SDL_TryLockRWLockForReading | ( | SDL_RWLock * | rwlock | ) |
Try to lock a read/write lock for reading without blocking.
This works just like SDL_LockRWLockForReading(), but if the rwlock is not available, then this function returns false immediately.
This technique is useful if you need access to a resource but don't want to wait for it, and will return to it to try again later.
Trying to lock for read-only access can succeed if other threads are holding read-only locks, as this won't prevent access.
This function returns true if passed a NULL rwlock.
rwlock | the rwlock to try to lock. |
bool SDL_TryLockRWLockForWriting | ( | SDL_RWLock * | rwlock | ) |
Try to lock a read/write lock for writing without blocking.
This works just like SDL_LockRWLockForWriting(), but if the rwlock is not available, then this function returns false 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.
It is illegal for the owning thread to lock an already-locked rwlock for writing (read-only may be locked recursively, writing can not). Doing so results in undefined behavior.
It is illegal to request a write lock from a thread that already holds a read-only lock. Doing so results in undefined behavior. Unlock the read-only lock before requesting a write lock.
This function returns true if passed a NULL rwlock.
rwlock | the rwlock to try to lock. |
bool SDL_TryWaitSemaphore | ( | SDL_Semaphore * | 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 false.
sem | the semaphore to wait on. |
void 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 illegal to unlock a mutex that has not been locked by the current thread, and doing so results in undefined behavior.
mutex | the mutex to unlock. |
void SDL_UnlockRWLock | ( | SDL_RWLock * | rwlock | ) |
Unlock the read/write lock.
Use this function to unlock the rwlock, whether it was locked for read-only or write operations.
It is legal for the owning thread to lock an already-locked read-only lock. 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 rwlock").
It is illegal to unlock a rwlock that has not been locked by the current thread, and doing so results in undefined behavior.
rwlock | the rwlock to unlock. |
void SDL_WaitCondition | ( | SDL_Condition * | cond, |
SDL_Mutex * | mutex | ||
) |
Wait until a condition variable is signaled.
This function unlocks the specified mutex
and waits for another thread to call SDL_SignalCondition() or SDL_BroadcastCondition() 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. Locking the mutex recursively (more than once) is not supported and leads to undefined behavior.
This function is the equivalent of calling SDL_WaitConditionTimeout() with a time length of -1.
cond | the condition variable to wait on. |
mutex | the mutex used to coordinate thread access. |
\threadsafety It is safe to call this function from any thread.
bool SDL_WaitConditionTimeout | ( | SDL_Condition * | cond, |
SDL_Mutex * | mutex, | ||
Sint32 | timeoutMS | ||
) |
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_SignalCondition() or SDL_BroadcastCondition() 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. Locking the mutex recursively (more than once) is not supported and leads to undefined behavior.
cond | the condition variable to wait on. |
mutex | the mutex used to coordinate thread access. |
timeoutMS | the maximum time to wait, in milliseconds, or -1 to wait indefinitely. |
\threadsafety It is safe to call this function from any thread.
void SDL_WaitSemaphore | ( | SDL_Semaphore * | sem | ) |
Wait until a semaphore has a positive value and then decrements it.
This function suspends the calling thread until the semaphore pointed to by sem
has a positive value, and then atomically decrement the semaphore value.
This function is the equivalent of calling SDL_WaitSemaphoreTimeout() with a time length of -1.
sem | the semaphore wait on. |
bool SDL_WaitSemaphoreTimeout | ( | SDL_Semaphore * | sem, |
Sint32 | timeoutMS | ||
) |
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 specified time has elapsed. If the call is successful it will atomically decrement the semaphore value.
sem | the semaphore to wait on. |
timeoutMS | the length of the timeout, in milliseconds, or -1 to wait indefinitely. |
bool mutex |
Definition at line 363 of file SDL_mutex.h.
bool rwlock |
Definition at line 562 of file SDL_mutex.h.