1 #include <common/spinlock.h> 2 #include <process/preempt.h> 3 __arch_spin_lock(spinlock_t * lock)4void __arch_spin_lock(spinlock_t *lock) 5 { 6 while(1); 7 rs_preempt_disable(); 8 } 9 __arch_spin_unlock(spinlock_t * lock)10void __arch_spin_unlock(spinlock_t *lock) 11 { 12 while(1); 13 rs_preempt_enable(); 14 } 15 __arch_spin_lock_no_preempt(spinlock_t * lock)16void __arch_spin_lock_no_preempt(spinlock_t *lock) 17 { 18 while(1); 19 } 20 __arch_spin_unlock_no_preempt(spinlock_t * lock)21void __arch_spin_unlock_no_preempt(spinlock_t *lock) 22 { 23 while(1); 24 } 25 __arch_spin_trylock(spinlock_t * lock)26long __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