mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-06 21:51:49 +00:00
We already have something to wrap pthread with mutex_[init,lock,unlock] calls. This patch creates a new struct mutex abstraction and moves everything to work with it. Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
40 lines
873 B
C
40 lines
873 B
C
#ifndef KVM__MUTEX_H
|
|
#define KVM__MUTEX_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "kvm/util.h"
|
|
|
|
/*
|
|
* Kernel-alike mutex API - to make it easier for kernel developers
|
|
* to write user-space code! :-)
|
|
*/
|
|
|
|
struct mutex {
|
|
pthread_mutex_t mutex;
|
|
};
|
|
#define MUTEX_INITIALIZER (struct mutex) { .mutex = PTHREAD_MUTEX_INITIALIZER }
|
|
|
|
#define DEFINE_MUTEX(mtx) struct mutex mtx = MUTEX_INITIALIZER
|
|
|
|
static inline void mutex_init(struct mutex *lock)
|
|
{
|
|
if (pthread_mutex_init(&lock->mutex, NULL) != 0)
|
|
die("unexpected pthread_mutex_init() failure!");
|
|
}
|
|
|
|
static inline void mutex_lock(struct mutex *lock)
|
|
{
|
|
if (pthread_mutex_lock(&lock->mutex) != 0)
|
|
die("unexpected pthread_mutex_lock() failure!");
|
|
|
|
}
|
|
|
|
static inline void mutex_unlock(struct mutex *lock)
|
|
{
|
|
if (pthread_mutex_unlock(&lock->mutex) != 0)
|
|
die("unexpected pthread_mutex_unlock() failure!");
|
|
}
|
|
|
|
#endif /* KVM__MUTEX_H */
|