Lines Matching refs:lock

16 void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,  in __raw_spin_lock_init()  argument
23 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); in __raw_spin_lock_init()
24 lockdep_init_map_wait(&lock->dep_map, name, key, 0, inner); in __raw_spin_lock_init()
26 lock->raw_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; in __raw_spin_lock_init()
27 lock->magic = SPINLOCK_MAGIC; in __raw_spin_lock_init()
28 lock->owner = SPINLOCK_OWNER_INIT; in __raw_spin_lock_init()
29 lock->owner_cpu = -1; in __raw_spin_lock_init()
35 void __rwlock_init(rwlock_t *lock, const char *name, in __rwlock_init() argument
42 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); in __rwlock_init()
43 lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_CONFIG); in __rwlock_init()
45 lock->raw_lock = (arch_rwlock_t) __ARCH_RW_LOCK_UNLOCKED; in __rwlock_init()
46 lock->magic = RWLOCK_MAGIC; in __rwlock_init()
47 lock->owner = SPINLOCK_OWNER_INIT; in __rwlock_init()
48 lock->owner_cpu = -1; in __rwlock_init()
54 static void spin_dump(raw_spinlock_t *lock, const char *msg) in spin_dump() argument
56 struct task_struct *owner = READ_ONCE(lock->owner); in spin_dump()
65 lock, READ_ONCE(lock->magic), in spin_dump()
68 READ_ONCE(lock->owner_cpu)); in spin_dump()
72 static void spin_bug(raw_spinlock_t *lock, const char *msg) in spin_bug() argument
77 spin_dump(lock, msg); in spin_bug()
80 #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) argument
83 debug_spin_lock_before(raw_spinlock_t *lock) in debug_spin_lock_before() argument
85 SPIN_BUG_ON(READ_ONCE(lock->magic) != SPINLOCK_MAGIC, lock, "bad magic"); in debug_spin_lock_before()
86 SPIN_BUG_ON(READ_ONCE(lock->owner) == current, lock, "recursion"); in debug_spin_lock_before()
87 SPIN_BUG_ON(READ_ONCE(lock->owner_cpu) == raw_smp_processor_id(), in debug_spin_lock_before()
88 lock, "cpu recursion"); in debug_spin_lock_before()
91 static inline void debug_spin_lock_after(raw_spinlock_t *lock) in debug_spin_lock_after() argument
93 WRITE_ONCE(lock->owner_cpu, raw_smp_processor_id()); in debug_spin_lock_after()
94 WRITE_ONCE(lock->owner, current); in debug_spin_lock_after()
97 static inline void debug_spin_unlock(raw_spinlock_t *lock) in debug_spin_unlock() argument
99 SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); in debug_spin_unlock()
100 SPIN_BUG_ON(!raw_spin_is_locked(lock), lock, "already unlocked"); in debug_spin_unlock()
101 SPIN_BUG_ON(lock->owner != current, lock, "wrong owner"); in debug_spin_unlock()
102 SPIN_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), in debug_spin_unlock()
103 lock, "wrong CPU"); in debug_spin_unlock()
104 WRITE_ONCE(lock->owner, SPINLOCK_OWNER_INIT); in debug_spin_unlock()
105 WRITE_ONCE(lock->owner_cpu, -1); in debug_spin_unlock()
112 void do_raw_spin_lock(raw_spinlock_t *lock) in do_raw_spin_lock() argument
114 debug_spin_lock_before(lock); in do_raw_spin_lock()
115 arch_spin_lock(&lock->raw_lock); in do_raw_spin_lock()
117 debug_spin_lock_after(lock); in do_raw_spin_lock()
120 int do_raw_spin_trylock(raw_spinlock_t *lock) in do_raw_spin_trylock() argument
122 int ret = arch_spin_trylock(&lock->raw_lock); in do_raw_spin_trylock()
126 debug_spin_lock_after(lock); in do_raw_spin_trylock()
132 SPIN_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_spin_trylock()
137 void do_raw_spin_unlock(raw_spinlock_t *lock) in do_raw_spin_unlock() argument
140 debug_spin_unlock(lock); in do_raw_spin_unlock()
141 arch_spin_unlock(&lock->raw_lock); in do_raw_spin_unlock()
145 static void rwlock_bug(rwlock_t *lock, const char *msg) in rwlock_bug() argument
152 task_pid_nr(current), lock); in rwlock_bug()
156 #define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg) argument
158 void do_raw_read_lock(rwlock_t *lock) in do_raw_read_lock() argument
160 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in do_raw_read_lock()
161 arch_read_lock(&lock->raw_lock); in do_raw_read_lock()
164 int do_raw_read_trylock(rwlock_t *lock) in do_raw_read_trylock() argument
166 int ret = arch_read_trylock(&lock->raw_lock); in do_raw_read_trylock()
172 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_read_trylock()
177 void do_raw_read_unlock(rwlock_t *lock) in do_raw_read_unlock() argument
179 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in do_raw_read_unlock()
180 arch_read_unlock(&lock->raw_lock); in do_raw_read_unlock()
183 static inline void debug_write_lock_before(rwlock_t *lock) in debug_write_lock_before() argument
185 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in debug_write_lock_before()
186 RWLOCK_BUG_ON(lock->owner == current, lock, "recursion"); in debug_write_lock_before()
187 RWLOCK_BUG_ON(lock->owner_cpu == raw_smp_processor_id(), in debug_write_lock_before()
188 lock, "cpu recursion"); in debug_write_lock_before()
191 static inline void debug_write_lock_after(rwlock_t *lock) in debug_write_lock_after() argument
193 WRITE_ONCE(lock->owner_cpu, raw_smp_processor_id()); in debug_write_lock_after()
194 WRITE_ONCE(lock->owner, current); in debug_write_lock_after()
197 static inline void debug_write_unlock(rwlock_t *lock) in debug_write_unlock() argument
199 RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); in debug_write_unlock()
200 RWLOCK_BUG_ON(lock->owner != current, lock, "wrong owner"); in debug_write_unlock()
201 RWLOCK_BUG_ON(lock->owner_cpu != raw_smp_processor_id(), in debug_write_unlock()
202 lock, "wrong CPU"); in debug_write_unlock()
203 WRITE_ONCE(lock->owner, SPINLOCK_OWNER_INIT); in debug_write_unlock()
204 WRITE_ONCE(lock->owner_cpu, -1); in debug_write_unlock()
207 void do_raw_write_lock(rwlock_t *lock) in do_raw_write_lock() argument
209 debug_write_lock_before(lock); in do_raw_write_lock()
210 arch_write_lock(&lock->raw_lock); in do_raw_write_lock()
211 debug_write_lock_after(lock); in do_raw_write_lock()
214 int do_raw_write_trylock(rwlock_t *lock) in do_raw_write_trylock() argument
216 int ret = arch_write_trylock(&lock->raw_lock); in do_raw_write_trylock()
219 debug_write_lock_after(lock); in do_raw_write_trylock()
224 RWLOCK_BUG_ON(!ret, lock, "trylock failure on UP"); in do_raw_write_trylock()
229 void do_raw_write_unlock(rwlock_t *lock) in do_raw_write_unlock() argument
231 debug_write_unlock(lock); in do_raw_write_unlock()
232 arch_write_unlock(&lock->raw_lock); in do_raw_write_unlock()