mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-08-21 12:57:49 +00:00
a009444e08
Adds a rwlock wrapper which like the mutex wrapper makes rwlock calls similar to their kernel counterparts. Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
40 lines
911 B
C
40 lines
911 B
C
#ifndef KVM__RWSEM_H
|
|
#define KVM__RWSEM_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#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 */
|