This commit is contained in:
nora 2022-03-22 09:56:35 +01:00
parent 25ac075ef1
commit 972c8f6970

View file

@ -28,6 +28,22 @@ impl<T> Mutex<T> {
None None
} }
} }
pub fn lock(&self) -> MutexGuard<'_, T> {
// hahahahahahahaha a spin loop :D
// don't use spin loops
// but I can't be bothered with the proper solution
loop {
if self
.status
.compare_exchange(INIT, ACQUIRED, Ordering::Acquire, Ordering::Relaxed)
{
return MutexGuard { mutex: self };
} else {
std::hint::spin_loop();
}
}
}
} }
pub struct MutexGuard<'a, T> { pub struct MutexGuard<'a, T> {