Small fixes
This commit is contained in:
+10
@@ -17,6 +17,16 @@ void spin_lock(struct spinlock* spin) {
|
||||
}
|
||||
}
|
||||
|
||||
bool spin_trylock(struct spinlock* spin) {
|
||||
irq_lock();
|
||||
uint32_t owner = atomic_load(&spin->owner, ATOMIC_RELAXED);
|
||||
uint32_t expected = owner;
|
||||
if (atomic_compare_exchange(&spin->next, &expected, owner + 1, ATOMIC_ACQUIRE, ATOMIC_RELAXED))
|
||||
return true;
|
||||
irq_unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
void spin_unlock(struct spinlock* spin) {
|
||||
uint32_t val = atomic_load(&spin->owner, ATOMIC_RELAXED);
|
||||
atomic_store(&spin->owner, val + 1, ATOMIC_RELEASE);
|
||||
|
||||
Reference in New Issue
Block a user