mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-05-23 16:31:20 -04:00
wrap mutex type to enable future optimization
This commit is contained in:
parent
fc2473e7ee
commit
49af83a817
3 changed files with 78 additions and 56 deletions
28
mutex.h
Normal file
28
mutex.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue