work
This commit is contained in:
19
kernel/src/util/spin.rs
Normal file
19
kernel/src/util/spin.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user