From 1e8960c97d8840d014cbf428cfc3756aecf5b50b Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Mon, 30 May 2011 20:27:56 +0300 Subject: [PATCH] kvm tools: Add rwlock wrapper Adds a rwlock wrapper which like the mutex wrapper makes rwlock calls similar to their kernel counterparts. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/include/kvm/rwsem.h | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tools/kvm/include/kvm/rwsem.h diff --git a/tools/kvm/include/kvm/rwsem.h b/tools/kvm/include/kvm/rwsem.h new file mode 100644 index 000000000000..75a22f835d20 --- /dev/null +++ b/tools/kvm/include/kvm/rwsem.h @@ -0,0 +1,39 @@ +#ifndef KVM__RWSEM_H +#define KVM__RWSEM_H + +#include + +#include "kvm/util.h" + +/* + * Kernel-alike rwsem API - to make it easier for kernel developers + * to write user-space code! :-) + */ + +#define DECLARE_RWSEM(sem) pthread_rwlock_t sem = PTHREAD_RWLOCK_INITIALIZER + +static inline void down_read(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_rdlock(rwsem) != 0) + die("unexpected pthread_rwlock_rdlock() failure!"); +} + +static inline void down_write(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_wrlock(rwsem) != 0) + die("unexpected pthread_rwlock_wrlock() failure!"); +} + +static inline void up_read(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_unlock(rwsem) != 0) + die("unexpected pthread_rwlock_unlock() failure!"); +} + +static inline void up_write(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_unlock(rwsem) != 0) + die("unexpected pthread_rwlock_unlock() failure!"); +} + +#endif /* KVM__RWSEM_H */ -- 2.39.5