hardened_malloc/mutex.h
2018-09-07 01:13:08 -04:00

29 lines
537 B
C

#ifndef MUTEX_H
#define MUTEX_H
#include <pthread.h>
#include "util.h"
struct mutex {
pthread_mutex_t lock;
};
#define MUTEX_INITIALIZER (struct mutex){PTHREAD_MUTEX_INITIALIZER}
static inline void mutex_init(struct mutex *m) {
if (unlikely(pthread_mutex_init(&m->lock, NULL))) {
fatal_error("mutex initialization failed");
}
}
static inline void mutex_lock(struct mutex *m) {
pthread_mutex_lock(&m->lock);
}
static inline void mutex_unlock(struct mutex *m) {
pthread_mutex_unlock(&m->lock);
}
#endif