mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-10-01 01:36:01 -04:00
29 lines
537 B
C
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
|