runtime: fix yield_calls_park_before_scheduling_again test (#6679)

This commit is contained in:
Evan Rittenhouse
2024-07-16 17:29:19 +02:00
committed by GitHub
parent 15925efe43
commit 1e286689ff
3 changed files with 11 additions and 2 deletions
+1 -1
View File
@@ -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 ====
@@ -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<Inner>,
}
@@ -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));
}
}
@@ -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();