Skip to content

Commit

Permalink
replace spin_loop_hint with hint::spin_loop (#4491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Name1e5s authored Feb 12, 2022
1 parent 62274b0 commit 02141db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions tokio/src/loom/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub(crate) mod future {
pub(crate) use crate::sync::AtomicWaker;
}

pub(crate) mod hint {
pub(crate) use std::hint::spin_loop;
}

pub(crate) mod rand {
use std::collections::hash_map::RandomState;
use std::hash::{BuildHasher, Hash, Hasher};
Expand Down Expand Up @@ -75,9 +79,6 @@ pub(crate) mod sync {
pub(crate) use crate::loom::std::atomic_usize::AtomicUsize;

pub(crate) use std::sync::atomic::{fence, AtomicBool, Ordering};
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
pub(crate) use std::sync::atomic::spin_loop_hint;
}
}

Expand All @@ -96,9 +97,7 @@ pub(crate) mod sys {
pub(crate) mod thread {
#[inline]
pub(crate) fn yield_now() {
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
std::sync::atomic::spin_loop_hint();
std::hint::spin_loop();
}

#[allow(unused_imports)]
Expand Down
7 changes: 3 additions & 4 deletions tokio/src/sync/task/atomic_waker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![cfg_attr(any(loom, not(feature = "sync")), allow(dead_code, unreachable_pub))]

use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{self, AtomicUsize};
use crate::loom::hint;
use crate::loom::sync::atomic::AtomicUsize;

use std::fmt;
use std::panic::{resume_unwind, AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
Expand Down Expand Up @@ -281,9 +282,7 @@ impl AtomicWaker {
waker.wake();

// This is equivalent to a spin lock, so use a spin hint.
// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[allow(deprecated)]
atomic::spin_loop_hint();
hint::spin_loop();
}
state => {
// In this case, a concurrent thread is holding the
Expand Down

0 comments on commit 02141db

Please sign in to comment.