mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-11-04 09:46:32 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
	
		
			537 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			28 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
 |