Skip to content

Commit

Permalink
6536 - fix yield_calls_park_before_scheduling_again test
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Jul 9, 2024
1 parent c8f3539 commit 28b01bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tokio/src/runtime/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ====
Expand Down
10 changes: 10 additions & 0 deletions tokio/src/runtime/scheduler/multi_thread/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
1 change: 0 additions & 1 deletion tokio/src/runtime/tests/loom_multi_thread/yield_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 28b01bd

Please sign in to comment.