wrap mutex type to enable future optimization

This commit is contained in:
Daniel Micay 2018-09-07 01:08:51 -04:00
parent fc2473e7ee
commit 49af83a817
3 changed files with 78 additions and 56 deletions

28
mutex.h Normal file
View file

@ -0,0 +1,28 @@
#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