1
2
3
4
5
6
7#ifndef _LINUX_RWSEM_H
8#define _LINUX_RWSEM_H
9
10#include <linux/linkage.h>
11
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/list.h>
15#include <linux/spinlock.h>
16
17#include <linux/atomic.h>
18
19struct rw_semaphore;
20
21#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
22#include <linux/rwsem-spinlock.h>
23#else
24
25struct rw_semaphore {
26 long count;
27 raw_spinlock_t wait_lock;
28 struct list_head wait_list;
29#ifdef CONFIG_DEBUG_LOCK_ALLOC
30 struct lockdep_map dep_map;
31#endif
32};
33
34extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem);
35extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem);
36extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *);
37extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem);
38
39
40#include <asm/rwsem.h>
41
42
43static inline int rwsem_is_locked(struct rw_semaphore *sem)
44{
45 return sem->count != 0;
46}
47
48#endif
49
50
51
52#ifdef CONFIG_DEBUG_LOCK_ALLOC
53# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
54#else
55# define __RWSEM_DEP_MAP_INIT(lockname)
56#endif
57
58#define __RWSEM_INITIALIZER(name) \
59 { RWSEM_UNLOCKED_VALUE, \
60 __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
61 LIST_HEAD_INIT((name).wait_list) \
62 __RWSEM_DEP_MAP_INIT(name) }
63
64#define DECLARE_RWSEM(name) \
65 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
66
67extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
68 struct lock_class_key *key);
69
70#define init_rwsem(sem) \
71do { \
72 static struct lock_class_key __key; \
73 \
74 __init_rwsem((sem), #sem, &__key); \
75} while (0)
76
77
78
79
80extern void down_read(struct rw_semaphore *sem);
81
82
83
84
85extern int down_read_trylock(struct rw_semaphore *sem);
86
87
88
89
90extern void down_write(struct rw_semaphore *sem);
91
92
93
94
95extern int down_write_trylock(struct rw_semaphore *sem);
96
97
98
99
100extern void up_read(struct rw_semaphore *sem);
101
102
103
104
105extern void up_write(struct rw_semaphore *sem);
106
107
108
109
110extern void downgrade_write(struct rw_semaphore *sem);
111
112#ifdef CONFIG_DEBUG_LOCK_ALLOC
113
114
115
116
117
118
119
120
121
122
123
124
125
126extern void down_read_nested(struct rw_semaphore *sem, int subclass);
127extern void down_write_nested(struct rw_semaphore *sem, int subclass);
128#else
129# define down_read_nested(sem, subclass) down_read(sem)
130# define down_write_nested(sem, subclass) down_write(sem)
131#endif
132
133#endif
134