1
2
3
4
5
6
7
8
9
10#ifndef __LINUX_MUTEX_H
11#define __LINUX_MUTEX_H
12
13#include <linux/list.h>
14#include <linux/spinlock_types.h>
15#include <linux/linkage.h>
16#include <linux/lockdep.h>
17
18#include <asm/atomic.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47struct mutex {
48
49 atomic_t count;
50 spinlock_t wait_lock;
51 struct list_head wait_list;
52#ifdef CONFIG_DEBUG_MUTEXES
53 struct thread_info *owner;
54 const char *name;
55 void *magic;
56#endif
57#ifdef CONFIG_DEBUG_LOCK_ALLOC
58 struct lockdep_map dep_map;
59#endif
60};
61
62
63
64
65
66struct mutex_waiter {
67 struct list_head list;
68 struct task_struct *task;
69#ifdef CONFIG_DEBUG_MUTEXES
70 struct mutex *lock;
71 void *magic;
72#endif
73};
74
75#ifdef CONFIG_DEBUG_MUTEXES
76# include <linux/mutex-debug.h>
77#else
78# define __DEBUG_MUTEX_INITIALIZER(lockname)
79# define mutex_init(mutex) \
80do { \
81 static struct lock_class_key __key; \
82 \
83 __mutex_init((mutex), #mutex, &__key); \
84} while (0)
85# define mutex_destroy(mutex) do { } while (0)
86#endif
87
88#ifdef CONFIG_DEBUG_LOCK_ALLOC
89# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
90 , .dep_map = { .name = #lockname }
91#else
92# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
93#endif
94
95#define __MUTEX_INITIALIZER(lockname) \
96 { .count = ATOMIC_INIT(1) \
97 , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
98 , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
99 __DEBUG_MUTEX_INITIALIZER(lockname) \
100 __DEP_MAP_MUTEX_INITIALIZER(lockname) }
101
102#define DEFINE_MUTEX(mutexname) \
103 struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
104
105extern void __mutex_init(struct mutex *lock, const char *name,
106 struct lock_class_key *key);
107
108
109
110
111
112
113
114static inline int fastcall mutex_is_locked(struct mutex *lock)
115{
116 return atomic_read(&lock->count) != 1;
117}
118
119
120
121
122
123extern void fastcall mutex_lock(struct mutex *lock);
124extern int __must_check fastcall mutex_lock_interruptible(struct mutex *lock);
125
126#ifdef CONFIG_DEBUG_LOCK_ALLOC
127extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
128extern int __must_check mutex_lock_interruptible_nested(struct mutex *lock,
129 unsigned int subclass);
130#else
131# define mutex_lock_nested(lock, subclass) mutex_lock(lock)
132# define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
133#endif
134
135
136
137
138
139extern int fastcall mutex_trylock(struct mutex *lock);
140extern void fastcall mutex_unlock(struct mutex *lock);
141
142#endif
143