Lines Matching +full:lock +full:- +full:- +full:- +full:-

1 /* SPDX-License-Identifier: GPL-2.0 */
7 * include/linux/spinlock.h - generic spinlock/rwlock declarations
24 * (also included on UP-debug builds:)
35 * (which is an empty structure on non-debug builds)
44 * builds. (which are NOPs on non-debug, non-preempt
47 * (included on UP-non-debug builds:)
72 #define LOCK_SECTION_NAME ".text..lock."KBUILD_BASENAME
92 * Pull the arch_spin*() functions/declarations (UP-nondebug doesn't need them):
101 extern void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
104 # define raw_spin_lock_init(lock) \ argument
108 __raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN); \
112 # define raw_spin_lock_init(lock) \ argument
113 do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); } while (0)
116 #define raw_spin_is_locked(lock) arch_spin_is_locked(&(lock)->raw_lock) argument
119 #define raw_spin_is_contended(lock) arch_spin_is_contended(&(lock)->raw_lock) argument
121 #define raw_spin_is_contended(lock) (((void)(lock), 0)) argument
126 * between program-order earlier lock acquisitions and program-order later
166 * Property (2) upgrades the lock to an RCsc lock.
168 * Since most load-store architectures implement ACQUIRE with an smp_mb() after
180 extern void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
181 extern int do_raw_spin_trylock(raw_spinlock_t *lock);
182 extern void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock);
184 static inline void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock) in do_raw_spin_lock() argument
186 __acquire(lock); in do_raw_spin_lock()
187 arch_spin_lock(&lock->raw_lock); in do_raw_spin_lock()
191 static inline int do_raw_spin_trylock(raw_spinlock_t *lock) in do_raw_spin_trylock() argument
193 int ret = arch_spin_trylock(&(lock)->raw_lock); in do_raw_spin_trylock()
201 static inline void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock) in do_raw_spin_unlock() argument
204 arch_spin_unlock(&lock->raw_lock); in do_raw_spin_unlock()
205 __release(lock); in do_raw_spin_unlock()
215 #define raw_spin_trylock(lock) __cond_lock(lock, _raw_spin_trylock(lock)) argument
217 #define raw_spin_lock(lock) _raw_spin_lock(lock) argument
220 # define raw_spin_lock_nested(lock, subclass) \ argument
221 _raw_spin_lock_nested(lock, subclass)
223 # define raw_spin_lock_nest_lock(lock, nest_lock) \ argument
225 typecheck(struct lockdep_map *, &(nest_lock)->dep_map);\
226 _raw_spin_lock_nest_lock(lock, &(nest_lock)->dep_map); \
231 * warns about set-but-not-used variables when building with
234 # define raw_spin_lock_nested(lock, subclass) \ argument
235 _raw_spin_lock(((void)(subclass), (lock)))
236 # define raw_spin_lock_nest_lock(lock, nest_lock) _raw_spin_lock(lock) argument
241 #define raw_spin_lock_irqsave(lock, flags) \ argument
244 flags = _raw_spin_lock_irqsave(lock); \
248 #define raw_spin_lock_irqsave_nested(lock, flags, subclass) \ argument
251 flags = _raw_spin_lock_irqsave_nested(lock, subclass); \
254 #define raw_spin_lock_irqsave_nested(lock, flags, subclass) \ argument
257 flags = _raw_spin_lock_irqsave(lock); \
263 #define raw_spin_lock_irqsave(lock, flags) \ argument
266 _raw_spin_lock_irqsave(lock, flags); \
269 #define raw_spin_lock_irqsave_nested(lock, flags, subclass) \ argument
270 raw_spin_lock_irqsave(lock, flags)
274 #define raw_spin_lock_irq(lock) _raw_spin_lock_irq(lock) argument
275 #define raw_spin_lock_bh(lock) _raw_spin_lock_bh(lock) argument
276 #define raw_spin_unlock(lock) _raw_spin_unlock(lock) argument
277 #define raw_spin_unlock_irq(lock) _raw_spin_unlock_irq(lock) argument
279 #define raw_spin_unlock_irqrestore(lock, flags) \ argument
282 _raw_spin_unlock_irqrestore(lock, flags); \
284 #define raw_spin_unlock_bh(lock) _raw_spin_unlock_bh(lock) argument
286 #define raw_spin_trylock_bh(lock) \ argument
287 __cond_lock(lock, _raw_spin_trylock_bh(lock))
289 #define raw_spin_trylock_irq(lock) \ argument
292 raw_spin_trylock(lock) ? \
296 #define raw_spin_trylock_irqsave(lock, flags) \ argument
299 raw_spin_trylock(lock) ? \
324 static __always_inline raw_spinlock_t *spinlock_check(spinlock_t *lock) in spinlock_check() argument
326 return &lock->rlock; in spinlock_check()
331 # define spin_lock_init(lock) \ argument
335 __raw_spin_lock_init(spinlock_check(lock), \
336 #lock, &__key, LD_WAIT_CONFIG); \
349 static __always_inline void spin_lock(spinlock_t *lock) in spin_lock() argument
351 raw_spin_lock(&lock->rlock); in spin_lock()
354 static __always_inline void spin_lock_bh(spinlock_t *lock) in spin_lock_bh() argument
356 raw_spin_lock_bh(&lock->rlock); in spin_lock_bh()
359 static __always_inline int spin_trylock(spinlock_t *lock) in spin_trylock() argument
361 return raw_spin_trylock(&lock->rlock); in spin_trylock()
364 #define spin_lock_nested(lock, subclass) \ argument
366 raw_spin_lock_nested(spinlock_check(lock), subclass); \
369 #define spin_lock_nest_lock(lock, nest_lock) \ argument
371 raw_spin_lock_nest_lock(spinlock_check(lock), nest_lock); \
374 static __always_inline void spin_lock_irq(spinlock_t *lock) in spin_lock_irq() argument
376 raw_spin_lock_irq(&lock->rlock); in spin_lock_irq()
379 #define spin_lock_irqsave(lock, flags) \ argument
381 raw_spin_lock_irqsave(spinlock_check(lock), flags); \
384 #define spin_lock_irqsave_nested(lock, flags, subclass) \ argument
386 raw_spin_lock_irqsave_nested(spinlock_check(lock), flags, subclass); \
389 static __always_inline void spin_unlock(spinlock_t *lock) in spin_unlock() argument
391 raw_spin_unlock(&lock->rlock); in spin_unlock()
394 static __always_inline void spin_unlock_bh(spinlock_t *lock) in spin_unlock_bh() argument
396 raw_spin_unlock_bh(&lock->rlock); in spin_unlock_bh()
399 static __always_inline void spin_unlock_irq(spinlock_t *lock) in spin_unlock_irq() argument
401 raw_spin_unlock_irq(&lock->rlock); in spin_unlock_irq()
404 static __always_inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) in spin_unlock_irqrestore() argument
406 raw_spin_unlock_irqrestore(&lock->rlock, flags); in spin_unlock_irqrestore()
409 static __always_inline int spin_trylock_bh(spinlock_t *lock) in spin_trylock_bh() argument
411 return raw_spin_trylock_bh(&lock->rlock); in spin_trylock_bh()
414 static __always_inline int spin_trylock_irq(spinlock_t *lock) in spin_trylock_irq() argument
416 return raw_spin_trylock_irq(&lock->rlock); in spin_trylock_irq()
419 #define spin_trylock_irqsave(lock, flags) \ argument
421 raw_spin_trylock_irqsave(spinlock_check(lock), flags); \
425 * spin_is_locked() - Check whether a spinlock is locked.
426 * @lock: Pointer to the spinlock.
433 * Returns: 1 if @lock is locked, 0 otherwise.
442 static __always_inline int spin_is_locked(spinlock_t *lock) in spin_is_locked() argument
444 return raw_spin_is_locked(&lock->rlock); in spin_is_locked()
447 static __always_inline int spin_is_contended(spinlock_t *lock) in spin_is_contended() argument
449 return raw_spin_is_contended(&lock->rlock); in spin_is_contended()
452 #define assert_spin_locked(lock) assert_raw_spin_locked(&(lock)->rlock) argument
463 static inline int spin_needbreak(spinlock_t *lock) in spin_needbreak() argument
468 return spin_is_contended(lock); in spin_needbreak()
473 * Returns non-zero if there is another task waiting on the rwlock.
474 * Returns zero if the lock is not contended or the system / underlying
479 static inline int rwlock_needbreak(rwlock_t *lock) in rwlock_needbreak() argument
484 return rwlock_is_contended(lock); in rwlock_needbreak()
489 * (asm-mips/atomic.h needs above definitions)
493 * atomic_dec_and_lock - lock on reaching reference count zero
495 * @lock: the spinlock in question
498 * @lock. Returns false for all other cases.
500 extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
501 #define atomic_dec_and_lock(atomic, lock) \ argument
502 __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
504 extern int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock,
506 #define atomic_dec_and_lock_irqsave(atomic, lock, flags) \ argument
507 __cond_lock(lock, _atomic_dec_and_lock_irqsave(atomic, lock, &(flags)))
509 extern int _atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock);
510 #define atomic_dec_and_raw_lock(atomic, lock) \ argument
511 __cond_lock(lock, _atomic_dec_and_raw_lock(atomic, lock))
513 extern int _atomic_dec_and_raw_lock_irqsave(atomic_t *atomic, raw_spinlock_t *lock,
515 #define atomic_dec_and_raw_lock_irqsave(atomic, lock, flags) \ argument
516 __cond_lock(lock, _atomic_dec_and_raw_lock_irqsave(atomic, lock, &(flags)))
536 raw_spin_lock(_T->lock),
537 raw_spin_unlock(_T->lock))
539 DEFINE_LOCK_GUARD_1_COND(raw_spinlock, _try, raw_spin_trylock(_T->lock))
542 raw_spin_lock_nested(_T->lock, SINGLE_DEPTH_NESTING),
543 raw_spin_unlock(_T->lock))
546 raw_spin_lock_irq(_T->lock),
547 raw_spin_unlock_irq(_T->lock))
549 DEFINE_LOCK_GUARD_1_COND(raw_spinlock_irq, _try, raw_spin_trylock_irq(_T->lock))
552 raw_spin_lock_irqsave(_T->lock, _T->flags),
553 raw_spin_unlock_irqrestore(_T->lock, _T->flags),
557 raw_spin_trylock_irqsave(_T->lock, _T->flags))
560 spin_lock(_T->lock),
561 spin_unlock(_T->lock))
563 DEFINE_LOCK_GUARD_1_COND(spinlock, _try, spin_trylock(_T->lock))
566 spin_lock_irq(_T->lock),
567 spin_unlock_irq(_T->lock))
570 spin_trylock_irq(_T->lock))
573 spin_lock_irqsave(_T->lock, _T->flags),
574 spin_unlock_irqrestore(_T->lock, _T->flags),
578 spin_trylock_irqsave(_T->lock, _T->flags))
581 read_lock(_T->lock),
582 read_unlock(_T->lock))
585 read_lock_irq(_T->lock),
586 read_unlock_irq(_T->lock))
589 read_lock_irqsave(_T->lock, _T->flags),
590 read_unlock_irqrestore(_T->lock, _T->flags),
594 write_lock(_T->lock),
595 write_unlock(_T->lock))
598 write_lock_irq(_T->lock),
599 write_unlock_irq(_T->lock))
602 write_lock_irqsave(_T->lock, _T->flags),
603 write_unlock_irqrestore(_T->lock, _T->flags),