disable interrupts while locked

This commit is contained in:
uosfz 2025-02-12 20:05:05 +01:00
parent bf16ead21f
commit 43f23cd7a2
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo

View file

@ -1,11 +1,13 @@
#include "sync.h"
void spin_lock(struct spinlock *s) {
__asm__ ("cli" :: );
while (atomic_exchange_explicit(&s->lock, 1, memory_order_acquire)) {
// spin
__asm__ ("pause" :: );
}
}
void spin_unlock(struct spinlock *s) {
atomic_store_explicit(&s->lock, 0, memory_order_release);
__asm__ ("sti" :: );
}