aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mutex.h')
-rw-r--r--include/linux/mutex.h83
1 files changed, 76 insertions, 7 deletions
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 878cab4f5fcc..f98509b26876 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -12,11 +12,85 @@
12 12
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/spinlock_types.h> 14#include <linux/spinlock_types.h>
15#include <linux/rt_lock.h>
15#include <linux/linkage.h> 16#include <linux/linkage.h>
16#include <linux/lockdep.h> 17#include <linux/lockdep.h>
17 18
18#include <asm/atomic.h> 19#include <asm/atomic.h>
19 20
21#ifdef CONFIG_DEBUG_LOCK_ALLOC
22# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
23 , .dep_map = { .name = #lockname }
24#else
25# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
26#endif
27
28#ifdef CONFIG_PREEMPT_RT
29
30#include <linux/rtmutex.h>
31
32struct mutex {
33 struct rt_mutex lock;
34#ifdef CONFIG_DEBUG_LOCK_ALLOC
35 struct lockdep_map dep_map;
36#endif
37};
38
39
40#define __MUTEX_INITIALIZER(mutexname) \
41 { \
42 .lock = __RT_MUTEX_INITIALIZER(mutexname.lock) \
43 __DEP_MAP_MUTEX_INITIALIZER(mutexname) \
44 }
45
46#define DEFINE_MUTEX(mutexname) \
47 struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
48
49extern void
50__mutex_init(struct mutex *lock, char *name, struct lock_class_key *key);
51
52extern void __lockfunc _mutex_lock(struct mutex *lock);
53extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
54extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
55extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
56extern int __lockfunc
57_mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
58extern int __lockfunc
59_mutex_lock_killable_nested(struct mutex *lock, int subclass);
60extern int __lockfunc _mutex_trylock(struct mutex *lock);
61extern void __lockfunc _mutex_unlock(struct mutex *lock);
62
63#define mutex_is_locked(l) rt_mutex_is_locked(&(l)->lock)
64#define mutex_lock(l) _mutex_lock(l)
65#define mutex_lock_interruptible(l) _mutex_lock_interruptible(l)
66#define mutex_lock_killable(l) _mutex_lock_killable(l)
67#define mutex_trylock(l) _mutex_trylock(l)
68#define mutex_unlock(l) _mutex_unlock(l)
69#define mutex_destroy(l) rt_mutex_destroy(&(l)->lock)
70
71#ifdef CONFIG_DEBUG_LOCK_ALLOC
72# define mutex_lock_nested(l, s) _mutex_lock_nested(l, s)
73# define mutex_lock_interruptible_nested(l, s) \
74 _mutex_lock_interruptible_nested(l, s)
75# define mutex_lock_killable_nested(l, s) \
76 _mutex_lock_killable_nested(l, s)
77#else
78# define mutex_lock_nested(l, s) _mutex_lock(l)
79# define mutex_lock_interruptible_nested(l, s) \
80 _mutex_lock_interruptible(l)
81# define mutex_lock_killable_nested(l, s) \
82 _mutex_lock_killable(l)
83#endif
84
85# define mutex_init(mutex) \
86do { \
87 static struct lock_class_key __key; \
88 \
89 __mutex_init((mutex), #mutex, &__key); \
90} while (0)
91
92#else /* PREEMPT_RT */
93
20/* 94/*
21 * Simple, straightforward mutexes with strict semantics: 95 * Simple, straightforward mutexes with strict semantics:
22 * 96 *
@@ -87,13 +161,6 @@ do { \
87# define mutex_destroy(mutex) do { } while (0) 161# define mutex_destroy(mutex) do { } while (0)
88#endif 162#endif
89 163
90#ifdef CONFIG_DEBUG_LOCK_ALLOC
91# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
92 , .dep_map = { .name = #lockname }
93#else
94# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
95#endif
96
97#define __MUTEX_INITIALIZER(lockname) \ 164#define __MUTEX_INITIALIZER(lockname) \
98 { .count = ATOMIC_INIT(1) \ 165 { .count = ATOMIC_INIT(1) \
99 , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ 166 , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
@@ -150,6 +217,8 @@ extern int __must_check mutex_lock_killable(struct mutex *lock);
150 */ 217 */
151extern int mutex_trylock(struct mutex *lock); 218extern int mutex_trylock(struct mutex *lock);
152extern void mutex_unlock(struct mutex *lock); 219extern void mutex_unlock(struct mutex *lock);
220#endif /* !PREEMPT_RT */
221
153extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock); 222extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
154 223
155#endif 224#endif