Move spinlock to separate folder
This commit is contained in:
20
kernel/spinlock/spinlock.c
Normal file
20
kernel/spinlock/spinlock.c
Normal 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user