diff options
author | Carl Lerche <me@carllerche.com> | 2019-12-11 12:44:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-11 12:44:45 -0800 |
commit | c0953d41a5cd2e0514b551771668139679332328 (patch) | |
tree | 65b244d8c033d4f39677fdf9d56cc862a4fc136b /tokio/src/runtime/park.rs | |
parent | 24cd6d67f76f122f67cbbb101d555018fc27820b (diff) |
chore: fix thread_pool benchmarks (#1947)
Update the rotted thread_pool benchmarks. These benchmarks are not the
greatest, but as of now it is all we have for micro benchmarks.
Adds a little yielding in the parker as it helps a bit.
Diffstat (limited to 'tokio/src/runtime/park.rs')
-rw-r--r-- | tokio/src/runtime/park.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tokio/src/runtime/park.rs b/tokio/src/runtime/park.rs index 7681e20f..1543bcb1 100644 --- a/tokio/src/runtime/park.rs +++ b/tokio/src/runtime/park.rs @@ -4,6 +4,7 @@ use crate::loom::sync::{Arc, Mutex, Condvar}; use crate::loom::sync::atomic::AtomicUsize; +use crate::loom::thread; use crate::park::{Park, Unpark}; use crate::runtime::time; use crate::util::TryLock; @@ -113,10 +114,14 @@ impl Unpark for Unparker { impl Inner { /// Park the current thread for at most `dur`. fn park(&self) { - // If we were previously notified then we consume this notification and - // return quickly. - if self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst).is_ok() { - return; + for _ in 0..3 { + // If we were previously notified then we consume this notification and + // return quickly. + if self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst).is_ok() { + return; + } + + thread::yield_now(); } if let Some(mut driver) = self.shared.driver.try_lock() { |