This commit is contained in:
Bryan McShea
2024-02-06 17:11:39 -05:00
parent f9e7f85a8c
commit 4cf2f5b29e
3 changed files with 50 additions and 0 deletions

19
kernel/src/util/spin.rs Normal file
View File

@@ -0,0 +1,19 @@
use core::sync::atomic::{AtomicBool, Ordering};
pub struct SpinLock {
pub locked: AtomicBool,
}
impl SpinLock {
pub fn new() -> Self {
Self {
locked: AtomicBool::new(false),
}
}
pub fn lock(&mut self) {
while self.locked.swap(true, Ordering::Acquire) {}
}
pub fn unlock(&mut self) {
self.locked.store(false, Ordering::Release)
}
}