Move spinlock to separate folder

This commit is contained in:
2025-08-13 22:19:11 +02:00
parent d4f06b4538
commit ce6b17d72b
7 changed files with 50 additions and 39 deletions

View File

@ -0,0 +1,20 @@
#include <stdatomic.h>
#include <stdint.h>
#include "spinlock.h"
void spinlock_init(SpinLock *sl) {
atomic_store(&sl->lock, false);
}
void spinlock_acquire(SpinLock *sl) {
bool unlocked = false;
while (!atomic_compare_exchange_weak(&sl->lock, &unlocked, true)) {
unlocked = false;
SPINLOCK_HINT();
}
}
void spinlock_release(SpinLock *sl) {
atomic_store(&sl->lock, false);
}