Small fixes

This commit is contained in:
2026-10-18 21:20:50 +02:00
parent 32f1ff25f7
commit 692d67e3cf
10 changed files with 46 additions and 4 deletions
+10
View File
@@ -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);