1 // SPDX-License-Identifier: GPL-2.0-only
2 #ifndef _LINUX_RWBASE_RT_H
3 #define _LINUX_RWBASE_RT_H
5 #include <linux/rtmutex.h>
6 #include <linux/atomic.h>
8 #define READER_BIAS (1U << 31)
9 #define WRITER_BIAS (1U << 30)
13 struct rt_mutex_base rtmutex;
16 #define __RWBASE_INITIALIZER(name) \
18 .readers = ATOMIC_INIT(READER_BIAS), \
19 .rtmutex = __RT_MUTEX_BASE_INITIALIZER(name.rtmutex), \
22 #define init_rwbase_rt(rwbase) \
24 rt_mutex_base_init(&(rwbase)->rtmutex); \
25 atomic_set(&(rwbase)->readers, READER_BIAS); \
29 static __always_inline bool rw_base_is_locked(struct rwbase_rt *rwb)
31 return atomic_read(&rwb->readers) != READER_BIAS;
34 static __always_inline bool rw_base_is_contended(struct rwbase_rt *rwb)
36 return atomic_read(&rwb->readers) > 0;
39 #endif /* _LINUX_RWBASE_RT_H */