1
Fork 0

deprecate atomic::spin_loop_hint in favour of hint::spin_loop

This commit is contained in:
Ashley Mannix 2021-01-13 14:39:19 +10:00 committed by KodrAus
parent da305a2b00
commit d65cb6ebce
4 changed files with 19 additions and 20 deletions

View file

@ -1,9 +1,10 @@
use crate::cell::UnsafeCell;
use crate::collections::VecDeque;
use crate::ffi::c_void;
use crate::hint;
use crate::ops::{Deref, DerefMut, Drop};
use crate::ptr;
use crate::sync::atomic::{spin_loop_hint, AtomicUsize, Ordering};
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sys::hermit::abi;
/// This type provides a lock based on busy waiting to realize mutual exclusion
@ -46,7 +47,7 @@ impl<T> Spinlock<T> {
fn obtain_lock(&self) {
let ticket = self.queue.fetch_add(1, Ordering::SeqCst) + 1;
while self.dequeue.load(Ordering::SeqCst) != ticket {
spin_loop_hint();
hint::spin_loop();
}
}

View file

@ -2,8 +2,9 @@
mod tests;
use crate::cell::UnsafeCell;
use crate::hint;
use crate::ops::{Deref, DerefMut};
use crate::sync::atomic::{spin_loop_hint, AtomicBool, Ordering};
use crate::sync::atomic::{AtomicBool, Ordering};
#[derive(Default)]
pub struct SpinMutex<T> {
@ -32,7 +33,7 @@ impl<T> SpinMutex<T> {
match self.try_lock() {
None => {
while self.lock.load(Ordering::Relaxed) {
spin_loop_hint()
hint::spin_loop()
}
}
Some(guard) => return guard,