Skip to content

Commit

Permalink
mpsc: use spin_loop_hint instead of yield_now (#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Sep 18, 2021
1 parent ddd33f2 commit f1b8967
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 14 additions & 1 deletion tokio/src/loom/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,17 @@ pub(crate) mod sys {
}
}

pub(crate) use std::thread;
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();
}

#[allow(unused_imports)]
pub(crate) use std::thread::{
current, panicking, park, park_timeout, sleep, spawn, Builder, JoinHandle, LocalKey,
Result, Thread, ThreadId,
};
}
6 changes: 0 additions & 6 deletions tokio/src/sync/mpsc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,7 @@ impl<T> Block<T> {
Err(curr) => curr,
};

#[cfg(all(test, loom))]
crate::loom::thread::yield_now();

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[cfg(not(all(test, loom)))]
#[allow(deprecated)]
std::sync::atomic::spin_loop_hint();
}
}
}
Expand Down

0 comments on commit f1b8967

Please sign in to comment.