Add cond_wait_timeout()

Add a "timed out" version of cond_wait().
This commit is contained in:
Romain Vimont 2019-06-07 16:54:31 +02:00
parent eda44b6068
commit d104d3bda9
2 changed files with 16 additions and 0 deletions

View file

@ -28,6 +28,16 @@ cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
}
}
int
cond_wait_timeout(SDL_cond *cond, SDL_mutex *mutex, uint32_t ms) {
int r = SDL_CondWaitTimeout(cond, mutex, ms);
if (r < 0) {
LOGC("Could not wait on condition with timeout");
abort();
}
return r;
}
void
cond_signal(SDL_cond *cond) {
if (SDL_CondSignal(cond)) {

View file

@ -1,6 +1,8 @@
#ifndef LOCKUTIL_H
#define LOCKUTIL_H
#include <stdint.h>
// forward declarations
typedef struct SDL_mutex SDL_mutex;
typedef struct SDL_cond SDL_cond;
@ -14,6 +16,10 @@ mutex_unlock(SDL_mutex *mutex);
void
cond_wait(SDL_cond *cond, SDL_mutex *mutex);
// return 0 or SDL_MUTEX_TIMEDOUT
int
cond_wait_timeout(SDL_cond *cond, SDL_mutex *mutex, uint32_t ms);
void
cond_signal(SDL_cond *cond);