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