Go to the documentation of this file.
10 #ifndef __LINUX_MUTEX_H
11 #define __LINUX_MUTEX_H
13 #include <linux/list.h>
15 #include <linux/linkage.h>
53 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
56 #ifdef CONFIG_DEBUG_MUTEXES
60 #ifdef CONFIG_DEBUG_LOCK_ALLOC
61 struct lockdep_map dep_map;
72 #ifdef CONFIG_DEBUG_MUTEXES
77 #ifdef CONFIG_DEBUG_MUTEXES
80 # define __DEBUG_MUTEX_INITIALIZER(lockname)
89 # define mutex_init(mutex) \
91 static struct lock_class_key __key; \
93 __mutex_init((mutex), #mutex, &__key); \
98 #ifdef CONFIG_DEBUG_LOCK_ALLOC
99 # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
100 , .dep_map = { .name = #lockname }
102 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
105 #define __MUTEX_INITIALIZER(lockname) \
106 { .count = ATOMIC_INIT(1) \
107 , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
108 , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
109 __DEBUG_MUTEX_INITIALIZER(lockname) \
110 __DEP_MAP_MUTEX_INITIALIZER(lockname) }
112 #define DEFINE_MUTEX(mutexname) \
113 struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
124 static inline int mutex_is_locked(
struct mutex *lock)
133 #ifdef CONFIG_DEBUG_LOCK_ALLOC
135 extern void _mutex_lock_nest_lock(
struct mutex *lock,
struct lockdep_map *nest_lock);
141 #define mutex_lock(lock) mutex_lock_nested(lock, 0)
142 #define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0)
143 #define mutex_lock_killable(lock) mutex_lock_killable_nested(lock, 0)
145 #define mutex_lock_nest_lock(lock, nest_lock) \
147 typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
148 _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
156 # define mutex_lock_nested(lock, subclass) mutex_lock(lock)
157 # define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
158 # define mutex_lock_killable_nested(lock, subclass) mutex_lock_killable(lock)
159 # define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
172 #ifndef CONFIG_HAVE_ARCH_MUTEX_CPU_RELAX
173 #define arch_mutex_cpu_relax() cpu_relax()