mirror of
https://github.com/Noratrieb/nuclear.git
synced 2026-01-14 07:45:01 +01:00
lock :D
This commit is contained in:
parent
25ac075ef1
commit
972c8f6970
1 changed files with 16 additions and 0 deletions
16
src/mutex.rs
16
src/mutex.rs
|
|
@ -28,6 +28,22 @@ impl<T> Mutex<T> {
|
|||
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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue