Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-only
2#ifndef __LINUX_RWLOCK_RT_H
3#define __LINUX_RWLOCK_RT_H
4
5#ifndef __LINUX_SPINLOCK_RT_H
6#error Do not #include directly. Use <linux/spinlock.h>.
7#endif
8
9#ifdef CONFIG_DEBUG_LOCK_ALLOC
10extern void __rt_rwlock_init(rwlock_t *rwlock, const char *name,
11 struct lock_class_key *key);
12#else
13static inline void __rt_rwlock_init(rwlock_t *rwlock, char *name,
14 struct lock_class_key *key)
15{
16}
17#endif
18
19#define rwlock_init(rwl) \
20do { \
21 static struct lock_class_key __key; \
22 \
23 init_rwbase_rt(&(rwl)->rwbase); \
24 __rt_rwlock_init(rwl, #rwl, &__key); \
25} while (0)
26
27extern void rt_read_lock(rwlock_t *rwlock);
28extern int rt_read_trylock(rwlock_t *rwlock);
29extern void rt_read_unlock(rwlock_t *rwlock);
30extern void rt_write_lock(rwlock_t *rwlock);
31extern int rt_write_trylock(rwlock_t *rwlock);
32extern void rt_write_unlock(rwlock_t *rwlock);
33
34static __always_inline void read_lock(rwlock_t *rwlock)
35{
36 rt_read_lock(rwlock);
37}
38
39static __always_inline void read_lock_bh(rwlock_t *rwlock)
40{
41 local_bh_disable();
42 rt_read_lock(rwlock);
43}
44
45static __always_inline void read_lock_irq(rwlock_t *rwlock)
46{
47 rt_read_lock(rwlock);
48}
49
50#define read_lock_irqsave(lock, flags) \
51 do { \
52 typecheck(unsigned long, flags); \
53 rt_read_lock(lock); \
54 flags = 0; \
55 } while (0)
56
57#define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
58
59static __always_inline void read_unlock(rwlock_t *rwlock)
60{
61 rt_read_unlock(rwlock);
62}
63
64static __always_inline void read_unlock_bh(rwlock_t *rwlock)
65{
66 rt_read_unlock(rwlock);
67 local_bh_enable();
68}
69
70static __always_inline void read_unlock_irq(rwlock_t *rwlock)
71{
72 rt_read_unlock(rwlock);
73}
74
75static __always_inline void read_unlock_irqrestore(rwlock_t *rwlock,
76 unsigned long flags)
77{
78 rt_read_unlock(rwlock);
79}
80
81static __always_inline void write_lock(rwlock_t *rwlock)
82{
83 rt_write_lock(rwlock);
84}
85
86static __always_inline void write_lock_bh(rwlock_t *rwlock)
87{
88 local_bh_disable();
89 rt_write_lock(rwlock);
90}
91
92static __always_inline void write_lock_irq(rwlock_t *rwlock)
93{
94 rt_write_lock(rwlock);
95}
96
97#define write_lock_irqsave(lock, flags) \
98 do { \
99 typecheck(unsigned long, flags); \
100 rt_write_lock(lock); \
101 flags = 0; \
102 } while (0)
103
104#define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
105
106#define write_trylock_irqsave(lock, flags) \
107({ \
108 int __locked; \
109 \
110 typecheck(unsigned long, flags); \
111 flags = 0; \
112 __locked = write_trylock(lock); \
113 __locked; \
114})
115
116static __always_inline void write_unlock(rwlock_t *rwlock)
117{
118 rt_write_unlock(rwlock);
119}
120
121static __always_inline void write_unlock_bh(rwlock_t *rwlock)
122{
123 rt_write_unlock(rwlock);
124 local_bh_enable();
125}
126
127static __always_inline void write_unlock_irq(rwlock_t *rwlock)
128{
129 rt_write_unlock(rwlock);
130}
131
132static __always_inline void write_unlock_irqrestore(rwlock_t *rwlock,
133 unsigned long flags)
134{
135 rt_write_unlock(rwlock);
136}
137
138#define rwlock_is_contended(lock) (((void)(lock), 0))
139
140#endif /* __LINUX_RWLOCK_RT_H */