xref: /linux/rust/helpers/spinlock.c (revision 1b5f3c51fbb8042efb314484b47b2092cdd40bf6)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/spinlock.h>
4 
5 void rust_helper___spin_lock_init(spinlock_t *lock, const char *name,
6 				  struct lock_class_key *key)
7 {
8 #ifdef CONFIG_DEBUG_SPINLOCK
9 # if defined(CONFIG_PREEMPT_RT)
10 	__spin_lock_init(lock, name, key, false);
11 # else /*!CONFIG_PREEMPT_RT */
12 	__raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
13 # endif /* CONFIG_PREEMPT_RT */
14 #else /* !CONFIG_DEBUG_SPINLOCK */
15 	spin_lock_init(lock);
16 #endif /* CONFIG_DEBUG_SPINLOCK */
17 }
18 
19 void rust_helper_spin_lock(spinlock_t *lock)
20 {
21 	spin_lock(lock);
22 }
23 
24 void rust_helper_spin_unlock(spinlock_t *lock)
25 {
26 	spin_unlock(lock);
27 }
28 
29 int rust_helper_spin_trylock(spinlock_t *lock)
30 {
31 	return spin_trylock(lock);
32 }
33 
34 void rust_helper_spin_assert_is_held(spinlock_t *lock)
35 {
36 	lockdep_assert_held(lock);
37 }
38