xref: /kvm-unit-tests/lib/asm-generic/spinlock.h (revision f98bf90c1344ea08a70611d018986b0f6be7d807)
1 #ifndef _ASM_GENERIC_SPINLOCK_H_
2 #define _ASM_GENERIC_SPINLOCK_H_
3 
4 struct spinlock {
5     unsigned int v;
6 };
7 
spin_lock(struct spinlock * lock)8 static inline void spin_lock(struct spinlock *lock)
9 {
10 	while (__sync_lock_test_and_set(&lock->v, 1));
11 }
12 
spin_unlock(struct spinlock * lock)13 static inline void spin_unlock(struct spinlock *lock)
14 {
15 	__sync_lock_release(&lock->v);
16 }
17 
18 #endif
19