1 #ifndef KVM__MUTEX_H 2 #define KVM__MUTEX_H 3 4 #include <pthread.h> 5 6 #include "kvm/util.h" 7 8 /* 9 * Kernel-alike mutex API - to make it easier for kernel developers 10 * to write user-space code! :-) 11 */ 12 13 #define DEFINE_MUTEX(mutex) pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER 14 15 static inline void mutex_init(pthread_mutex_t *mutex) 16 { 17 if (pthread_mutex_init(mutex, NULL) != 0) 18 die("unexpected pthread_mutex_init() failure!"); 19 } 20 21 static inline void mutex_lock(pthread_mutex_t *mutex) 22 { 23 if (pthread_mutex_lock(mutex) != 0) 24 die("unexpected pthread_mutex_lock() failure!"); 25 } 26 27 static inline void mutex_unlock(pthread_mutex_t *mutex) 28 { 29 if (pthread_mutex_unlock(mutex) != 0) 30 die("unexpected pthread_mutex_unlock() failure!"); 31 } 32 33 #endif /* KVM__MUTEX_H */ 34