1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_LOCAL_LOCK_H
3 # error "Do not include directly, include linux/local_lock.h"
6 #include <linux/percpu-defs.h>
7 #include <linux/lockdep.h>
10 #ifdef CONFIG_DEBUG_LOCK_ALLOC
11 struct lockdep_map dep_map;
12 struct task_struct *owner;
16 #ifdef CONFIG_DEBUG_LOCK_ALLOC
17 # define LL_DEP_MAP_INIT(lockname) \
20 .wait_type_inner = LD_WAIT_CONFIG, \
23 # define LL_DEP_MAP_INIT(lockname)
26 #define INIT_LOCAL_LOCK(lockname) { LL_DEP_MAP_INIT(lockname) }
28 #define __local_lock_init(lock) \
30 static struct lock_class_key __key; \
32 debug_check_no_locks_freed((void *)lock, sizeof(*lock));\
33 lockdep_init_map_wait(&(lock)->dep_map, #lock, &__key, 0, LD_WAIT_CONFIG);\
36 #ifdef CONFIG_DEBUG_LOCK_ALLOC
37 static inline void local_lock_acquire(local_lock_t *l)
39 lock_map_acquire(&l->dep_map);
40 DEBUG_LOCKS_WARN_ON(l->owner);
44 static inline void local_lock_release(local_lock_t *l)
46 DEBUG_LOCKS_WARN_ON(l->owner != current);
48 lock_map_release(&l->dep_map);
51 #else /* CONFIG_DEBUG_LOCK_ALLOC */
52 static inline void local_lock_acquire(local_lock_t *l) { }
53 static inline void local_lock_release(local_lock_t *l) { }
54 #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
56 #define __local_lock(lock) \
59 local_lock_acquire(this_cpu_ptr(lock)); \
62 #define __local_lock_irq(lock) \
64 local_irq_disable(); \
65 local_lock_acquire(this_cpu_ptr(lock)); \
68 #define __local_lock_irqsave(lock, flags) \
70 local_irq_save(flags); \
71 local_lock_acquire(this_cpu_ptr(lock)); \
74 #define __local_unlock(lock) \
76 local_lock_release(this_cpu_ptr(lock)); \
80 #define __local_unlock_irq(lock) \
82 local_lock_release(this_cpu_ptr(lock)); \
86 #define __local_unlock_irqrestore(lock, flags) \
88 local_lock_release(this_cpu_ptr(lock)); \
89 local_irq_restore(flags); \