Lines Matching refs:rwb
53 static __always_inline int rwbase_read_trylock(struct rwbase_rt *rwb) in rwbase_read_trylock() argument
61 for (r = atomic_read(&rwb->readers); r < 0;) { in rwbase_read_trylock()
62 if (likely(atomic_try_cmpxchg_acquire(&rwb->readers, &r, r + 1))) in rwbase_read_trylock()
68 static int __sched __rwbase_read_lock(struct rwbase_rt *rwb, in __rwbase_read_lock() argument
71 struct rt_mutex_base *rtm = &rwb->rtmutex; in __rwbase_read_lock()
107 trace_contention_begin(rwb, LCB_F_RT | LCB_F_READ); in __rwbase_read_lock()
123 atomic_inc(&rwb->readers); in __rwbase_read_lock()
128 trace_contention_end(rwb, ret); in __rwbase_read_lock()
133 static __always_inline int rwbase_read_lock(struct rwbase_rt *rwb, in rwbase_read_lock() argument
138 if (rwbase_read_trylock(rwb)) in rwbase_read_lock()
141 return __rwbase_read_lock(rwb, state); in rwbase_read_lock()
144 static void __sched __rwbase_read_unlock(struct rwbase_rt *rwb, in __rwbase_read_unlock() argument
147 struct rt_mutex_base *rtm = &rwb->rtmutex; in __rwbase_read_unlock()
168 static __always_inline void rwbase_read_unlock(struct rwbase_rt *rwb, in rwbase_read_unlock() argument
177 if (unlikely(atomic_dec_and_test(&rwb->readers))) in rwbase_read_unlock()
178 __rwbase_read_unlock(rwb, state); in rwbase_read_unlock()
181 static inline void __rwbase_write_unlock(struct rwbase_rt *rwb, int bias, in __rwbase_write_unlock() argument
184 struct rt_mutex_base *rtm = &rwb->rtmutex; in __rwbase_write_unlock()
190 (void)atomic_add_return_release(READER_BIAS - bias, &rwb->readers); in __rwbase_write_unlock()
195 static inline void rwbase_write_unlock(struct rwbase_rt *rwb) in rwbase_write_unlock() argument
197 struct rt_mutex_base *rtm = &rwb->rtmutex; in rwbase_write_unlock()
201 __rwbase_write_unlock(rwb, WRITER_BIAS, flags); in rwbase_write_unlock()
204 static inline void rwbase_write_downgrade(struct rwbase_rt *rwb) in rwbase_write_downgrade() argument
206 struct rt_mutex_base *rtm = &rwb->rtmutex; in rwbase_write_downgrade()
211 __rwbase_write_unlock(rwb, WRITER_BIAS - 1, flags); in rwbase_write_downgrade()
214 static inline bool __rwbase_write_trylock(struct rwbase_rt *rwb) in __rwbase_write_trylock() argument
217 lockdep_assert_held(&rwb->rtmutex.wait_lock); in __rwbase_write_trylock()
223 if (!atomic_read_acquire(&rwb->readers)) { in __rwbase_write_trylock()
224 atomic_set(&rwb->readers, WRITER_BIAS); in __rwbase_write_trylock()
231 static int __sched rwbase_write_lock(struct rwbase_rt *rwb, in rwbase_write_lock() argument
234 struct rt_mutex_base *rtm = &rwb->rtmutex; in rwbase_write_lock()
242 atomic_sub(READER_BIAS, &rwb->readers); in rwbase_write_lock()
247 if (__rwbase_write_trylock(rwb)) in rwbase_write_lock()
251 trace_contention_begin(rwb, LCB_F_RT | LCB_F_WRITE); in rwbase_write_lock()
256 __rwbase_write_unlock(rwb, 0, flags); in rwbase_write_lock()
258 trace_contention_end(rwb, -EINTR); in rwbase_write_lock()
262 if (__rwbase_write_trylock(rwb)) in rwbase_write_lock()
272 trace_contention_end(rwb, 0); in rwbase_write_lock()
280 static inline int rwbase_write_trylock(struct rwbase_rt *rwb) in rwbase_write_trylock() argument
282 struct rt_mutex_base *rtm = &rwb->rtmutex; in rwbase_write_trylock()
288 atomic_sub(READER_BIAS, &rwb->readers); in rwbase_write_trylock()
291 if (__rwbase_write_trylock(rwb)) { in rwbase_write_trylock()
295 __rwbase_write_unlock(rwb, 0, flags); in rwbase_write_trylock()