Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / include / linux / rwlock_rt.h
blob7d81fc6918ee863ad500f93f71a76f1974be6d42
1 // SPDX-License-Identifier: GPL-2.0-only
2 #ifndef __LINUX_RWLOCK_RT_H
3 #define __LINUX_RWLOCK_RT_H
5 #ifndef __LINUX_SPINLOCK_RT_H
6 #error Do not #include directly. Use <linux/spinlock.h>.
7 #endif
9 #ifdef CONFIG_DEBUG_LOCK_ALLOC
10 extern void __rt_rwlock_init(rwlock_t *rwlock, const char *name,
11 struct lock_class_key *key);
12 #else
13 static inline void __rt_rwlock_init(rwlock_t *rwlock, char *name,
14 struct lock_class_key *key)
17 #endif
19 #define rwlock_init(rwl) \
20 do { \
21 static struct lock_class_key __key; \
23 init_rwbase_rt(&(rwl)->rwbase); \
24 __rt_rwlock_init(rwl, #rwl, &__key); \
25 } while (0)
27 extern void rt_read_lock(rwlock_t *rwlock) __acquires(rwlock);
28 extern int rt_read_trylock(rwlock_t *rwlock);
29 extern void rt_read_unlock(rwlock_t *rwlock) __releases(rwlock);
30 extern void rt_write_lock(rwlock_t *rwlock) __acquires(rwlock);
31 extern void rt_write_lock_nested(rwlock_t *rwlock, int subclass) __acquires(rwlock);
32 extern int rt_write_trylock(rwlock_t *rwlock);
33 extern void rt_write_unlock(rwlock_t *rwlock) __releases(rwlock);
35 static __always_inline void read_lock(rwlock_t *rwlock)
37 rt_read_lock(rwlock);
40 static __always_inline void read_lock_bh(rwlock_t *rwlock)
42 local_bh_disable();
43 rt_read_lock(rwlock);
46 static __always_inline void read_lock_irq(rwlock_t *rwlock)
48 rt_read_lock(rwlock);
51 #define read_lock_irqsave(lock, flags) \
52 do { \
53 typecheck(unsigned long, flags); \
54 rt_read_lock(lock); \
55 flags = 0; \
56 } while (0)
58 #define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
60 static __always_inline void read_unlock(rwlock_t *rwlock)
62 rt_read_unlock(rwlock);
65 static __always_inline void read_unlock_bh(rwlock_t *rwlock)
67 rt_read_unlock(rwlock);
68 local_bh_enable();
71 static __always_inline void read_unlock_irq(rwlock_t *rwlock)
73 rt_read_unlock(rwlock);
76 static __always_inline void read_unlock_irqrestore(rwlock_t *rwlock,
77 unsigned long flags)
79 rt_read_unlock(rwlock);
82 static __always_inline void write_lock(rwlock_t *rwlock)
84 rt_write_lock(rwlock);
87 #ifdef CONFIG_DEBUG_LOCK_ALLOC
88 static __always_inline void write_lock_nested(rwlock_t *rwlock, int subclass)
90 rt_write_lock_nested(rwlock, subclass);
92 #else
93 #define write_lock_nested(lock, subclass) rt_write_lock(((void)(subclass), (lock)))
94 #endif
96 static __always_inline void write_lock_bh(rwlock_t *rwlock)
98 local_bh_disable();
99 rt_write_lock(rwlock);
102 static __always_inline void write_lock_irq(rwlock_t *rwlock)
104 rt_write_lock(rwlock);
107 #define write_lock_irqsave(lock, flags) \
108 do { \
109 typecheck(unsigned long, flags); \
110 rt_write_lock(lock); \
111 flags = 0; \
112 } while (0)
114 #define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
116 #define write_trylock_irqsave(lock, flags) \
117 ({ \
118 int __locked; \
120 typecheck(unsigned long, flags); \
121 flags = 0; \
122 __locked = write_trylock(lock); \
123 __locked; \
126 static __always_inline void write_unlock(rwlock_t *rwlock)
128 rt_write_unlock(rwlock);
131 static __always_inline void write_unlock_bh(rwlock_t *rwlock)
133 rt_write_unlock(rwlock);
134 local_bh_enable();
137 static __always_inline void write_unlock_irq(rwlock_t *rwlock)
139 rt_write_unlock(rwlock);
142 static __always_inline void write_unlock_irqrestore(rwlock_t *rwlock,
143 unsigned long flags)
145 rt_write_unlock(rwlock);
148 #define rwlock_is_contended(lock) (((void)(lock), 0))
150 #endif /* __LINUX_RWLOCK_RT_H */