diff --git a/tokio/src/runtime/park.rs b/tokio/src/runtime/park.rs index 2fa0f501c6d..cdc32dac50a 100644 --- a/tokio/src/runtime/park.rs +++ b/tokio/src/runtime/park.rs @@ -35,7 +35,7 @@ tokio_thread_local! { // Bit of a hack, but it is only for loom #[cfg(loom)] tokio_thread_local! { - static CURRENT_THREAD_PARK_COUNT: AtomicUsize = AtomicUsize::new(0); + pub(crate) static CURRENT_THREAD_PARK_COUNT: AtomicUsize = AtomicUsize::new(0); } // ==== impl ParkThread ==== diff --git a/tokio/src/runtime/scheduler/multi_thread/park.rs b/tokio/src/runtime/scheduler/multi_thread/park.rs index bc369387395..aacd9012cc3 100644 --- a/tokio/src/runtime/scheduler/multi_thread/park.rs +++ b/tokio/src/runtime/scheduler/multi_thread/park.rs @@ -10,6 +10,9 @@ use crate::util::TryLock; use std::sync::atomic::Ordering::SeqCst; use std::time::Duration; +#[cfg(loom)] +use crate::runtime::park::CURRENT_THREAD_PARK_COUNT; + pub(crate) struct Parker { inner: Arc, } @@ -73,6 +76,13 @@ impl Parker { if let Some(mut driver) = self.inner.shared.driver.try_lock() { driver.park_timeout(handle, duration); + } else { + // https://github.com/tokio-rs/tokio/issues/6536 + // Hacky, but it's just for loom tests. The counter gets incremented during + // `park_timeout`, but we still have to increment the counter if we can't acquire the + // lock. + #[cfg(loom)] + CURRENT_THREAD_PARK_COUNT.with(|count| count.fetch_add(1, SeqCst)); } } diff --git a/tokio/src/runtime/tests/loom_multi_thread/yield_now.rs b/tokio/src/runtime/tests/loom_multi_thread/yield_now.rs index f078669ddfa..ba506e5a408 100644 --- a/tokio/src/runtime/tests/loom_multi_thread/yield_now.rs +++ b/tokio/src/runtime/tests/loom_multi_thread/yield_now.rs @@ -3,7 +3,6 @@ use crate::runtime::tests::loom_oneshot as oneshot; use crate::runtime::{self, Runtime}; #[test] -#[ignore] fn yield_calls_park_before_scheduling_again() { // Don't need to check all permutations let mut loom = loom::model::Builder::default();