SDL
2.0
|
#include "../../SDL_internal.h"
#include "SDL_thread.h"
#include <chrono>
#include <condition_variable>
#include <ratio>
#include <system_error>
#include "SDL_sysmutex_c.h"
Go to the source code of this file.
Data Structures | |
struct | SDL_cond |
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_CondWaitTimeout (SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) |
int | SDL_CondWait (SDL_cond *cond, SDL_mutex *mutex) |
int SDL_CondBroadcast | ( | SDL_cond * | cond | ) |
Restart all threads that are waiting on the condition variable.
Definition at line 84 of file SDL_syscond.cpp.
References SDL_cond::cpp_cond, and SDL_SetError.
int SDL_CondSignal | ( | SDL_cond * | cond | ) |
Restart one of the threads that are waiting on the condition variable.
Definition at line 70 of file SDL_syscond.cpp.
References SDL_cond::cpp_cond, and SDL_SetError.
Wait on the condition variable, unlocking the provided mutex.
The mutex is re-locked once the condition variable is signaled.
Definition at line 159 of file SDL_syscond.cpp.
References SDL_CondWaitTimeout(), and SDL_MUTEX_MAXWAIT.
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 118 of file SDL_syscond.cpp.
References SDL_cond::cpp_cond, SDL_mutex::cpp_mutex, SDL_MUTEX_MAXWAIT, SDL_MUTEX_TIMEDOUT, and SDL_SetError.
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.cpp.
References SDL_cond::cond, NULL, SDL_OutOfMemory, and SDL_SetError.
Destroy a condition variable.
Definition at line 60 of file SDL_syscond.cpp.
References SDL_cond::cond.