xref: /DragonOS/kernel/src/arch/riscv64/asm/spinlock.c (revision 83ed0ebc293d5a10245089f627f52770fd5b9dd4)
1 #include <common/spinlock.h>
2 #include <process/preempt.h>
3 
4 void __arch_spin_lock(spinlock_t *lock)
5 {
6     while(1);
7     rs_preempt_disable();
8 }
9 
10 void __arch_spin_unlock(spinlock_t *lock)
11 {
12     while(1);
13     rs_preempt_enable();
14 }
15 
16 void __arch_spin_lock_no_preempt(spinlock_t *lock)
17 {
18     while(1);
19 }
20 
21 void __arch_spin_unlock_no_preempt(spinlock_t *lock)
22 {
23     while(1);
24 }
25 
26 long __arch_spin_trylock(spinlock_t *lock)
27 {
28     uint64_t tmp_val = 0;
29     rs_preempt_disable();
30     // 交换tmp_val和lock的值,若tmp_val==1则证明加锁成功
31     while(1);
32     if (!tmp_val)
33         rs_preempt_enable();
34     return tmp_val;
35 }
36