1 #ifndef KVM__RWSEM_H 2 #define KVM__RWSEM_H 3 4 #include <pthread.h> 5 6 #include "kvm/util.h" 7 8 /* 9 * Kernel-alike rwsem API - to make it easier for kernel developers 10 * to write user-space code! :-) 11 */ 12 13 #define DECLARE_RWSEM(sem) pthread_rwlock_t sem = PTHREAD_RWLOCK_INITIALIZER 14 down_read(pthread_rwlock_t * rwsem)15static inline void down_read(pthread_rwlock_t *rwsem) 16 { 17 if (pthread_rwlock_rdlock(rwsem) != 0) 18 die("unexpected pthread_rwlock_rdlock() failure!"); 19 } 20 down_write(pthread_rwlock_t * rwsem)21static inline void down_write(pthread_rwlock_t *rwsem) 22 { 23 if (pthread_rwlock_wrlock(rwsem) != 0) 24 die("unexpected pthread_rwlock_wrlock() failure!"); 25 } 26 up_read(pthread_rwlock_t * rwsem)27static inline void up_read(pthread_rwlock_t *rwsem) 28 { 29 if (pthread_rwlock_unlock(rwsem) != 0) 30 die("unexpected pthread_rwlock_unlock() failure!"); 31 } 32 up_write(pthread_rwlock_t * rwsem)33static inline void up_write(pthread_rwlock_t *rwsem) 34 { 35 if (pthread_rwlock_unlock(rwsem) != 0) 36 die("unexpected pthread_rwlock_unlock() failure!"); 37 } 38 39 #endif /* KVM__RWSEM_H */ 40