Assert return value of mutex functions
Mutex functions may only fail due to a programming error. Use assertions in debug builds, and ignore the value in release builds.
This commit is contained in:
parent
d0f5a7fd9f
commit
15a206b7fc
1 changed files with 31 additions and 9 deletions
|
@ -9,44 +9,66 @@
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
mutex_lock(SDL_mutex *mutex) {
|
mutex_lock(SDL_mutex *mutex) {
|
||||||
if (SDL_LockMutex(mutex)) {
|
int r = SDL_LockMutex(mutex);
|
||||||
LOGC("Could not lock mutex");
|
#ifndef NDEBUG
|
||||||
|
if (r) {
|
||||||
|
LOGC("Could not lock mutex: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
mutex_unlock(SDL_mutex *mutex) {
|
mutex_unlock(SDL_mutex *mutex) {
|
||||||
if (SDL_UnlockMutex(mutex)) {
|
int r = SDL_UnlockMutex(mutex);
|
||||||
LOGC("Could not unlock mutex");
|
#ifndef NDEBUG
|
||||||
|
if (r) {
|
||||||
|
LOGC("Could not unlock mutex: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
|
cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
|
||||||
if (SDL_CondWait(cond, mutex)) {
|
int r = SDL_CondWait(cond, mutex);
|
||||||
LOGC("Could not wait on condition");
|
#ifndef NDEBUG
|
||||||
|
if (r) {
|
||||||
|
LOGC("Could not wait on condition: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
cond_wait_timeout(SDL_cond *cond, SDL_mutex *mutex, uint32_t ms) {
|
cond_wait_timeout(SDL_cond *cond, SDL_mutex *mutex, uint32_t ms) {
|
||||||
int r = SDL_CondWaitTimeout(cond, mutex, ms);
|
int r = SDL_CondWaitTimeout(cond, mutex, ms);
|
||||||
|
#ifndef NDEBUG
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
LOGC("Could not wait on condition with timeout");
|
LOGC("Could not wait on condition with timeout: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
cond_signal(SDL_cond *cond) {
|
cond_signal(SDL_cond *cond) {
|
||||||
if (SDL_CondSignal(cond)) {
|
int r = SDL_CondSignal(cond);
|
||||||
LOGC("Could not signal a condition");
|
#ifndef NDEBUG
|
||||||
|
if (r) {
|
||||||
|
LOGC("Could not signal a condition: %s", SDL_GetError());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
(void) r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue