Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/mutex.h
Show All 31 Lines | |||||
#define _LINUX_MUTEX_H_ | #define _LINUX_MUTEX_H_ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
#include <linux/spinlock.h> | #include <linux/spinlock.h> | ||||
#include <asm/atomic.h> | |||||
typedef struct mutex { | typedef struct mutex { | ||||
struct sx sx; | struct sx sx; | ||||
} mutex_t; | } mutex_t; | ||||
/* | /* | ||||
* By defining CONFIG_NO_MUTEX_SKIP LinuxKPI mutexes and asserts will | * By defining CONFIG_NO_MUTEX_SKIP LinuxKPI mutexes and asserts will | ||||
* not be skipped during panic(). | * not be skipped during panic(). | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return ((struct thread *)SX_OWNER(m->sx.sx_lock) != NULL); | return ((struct thread *)SX_OWNER(m->sx.sx_lock) != NULL); | ||||
} | } | ||||
static inline bool | static inline bool | ||||
mutex_is_owned(mutex_t *m) | mutex_is_owned(mutex_t *m) | ||||
{ | { | ||||
return (sx_xlocked(&m->sx)); | return (sx_xlocked(&m->sx)); | ||||
} | |||||
static inline int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *m) | |||||
{ | |||||
if (atomic_dec_and_test(cnt)) { | |||||
mutex_lock(m); | |||||
return (1); | |||||
} | |||||
return (0); | |||||
} | } | ||||
#ifdef WITNESS_ALL | #ifdef WITNESS_ALL | ||||
/* NOTE: the maximum WITNESS name is 64 chars */ | /* NOTE: the maximum WITNESS name is 64 chars */ | ||||
#define __mutex_name(name, file, line) \ | #define __mutex_name(name, file, line) \ | ||||
(((const char *){file ":" #line "-" name}) + \ | (((const char *){file ":" #line "-" name}) + \ | ||||
(sizeof(file) > 16 ? sizeof(file) - 16 : 0)) | (sizeof(file) > 16 ? sizeof(file) - 16 : 0)) | ||||
#else | #else | ||||
Show All 27 Lines |