2018-08-15 23:13:39 +08:00
|
|
|
#include <lock_util.h>
|
2017-12-16 00:31:23 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
|
2018-02-13 17:10:18 +08:00
|
|
|
#include "log.h"
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
mutex_lock(SDL_mutex *mutex) {
|
2017-12-16 00:31:23 +08:00
|
|
|
if (SDL_LockMutex(mutex)) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGC("Could not lock mutex");
|
2017-12-16 00:31:23 +08:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
mutex_unlock(SDL_mutex *mutex) {
|
2017-12-16 00:31:23 +08:00
|
|
|
if (SDL_UnlockMutex(mutex)) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGC("Could not unlock mutex");
|
2017-12-16 00:31:23 +08:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
|
2017-12-16 00:31:23 +08:00
|
|
|
if (SDL_CondWait(cond, mutex)) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGC("Could not wait on condition");
|
2017-12-16 00:31:23 +08:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
cond_signal(SDL_cond *cond) {
|
2017-12-16 00:31:23 +08:00
|
|
|
if (SDL_CondSignal(cond)) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGC("Could not signal a condition");
|
2017-12-16 00:31:23 +08:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|