From 82d37de105c59214543e6bea376e3cbd4f4e0072 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 24 Jul 2024 09:46:19 +0000 Subject: [PATCH] start restoring parallel tests --- tests/parallel/main.rs | 3 --- tests/parallel/parallel_cycle_all_recover.rs | 12 +++++++----- tests/parallel/setup.rs | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/parallel/main.rs b/tests/parallel/main.rs index eaf1f25..e136c7a 100644 --- a/tests/parallel/main.rs +++ b/tests/parallel/main.rs @@ -1,7 +1,5 @@ -#[cfg(disabled)] mod setup; -#[cfg(disabled)] mod parallel_cycle_all_recover; #[cfg(disabled)] mod parallel_cycle_mid_recover; @@ -9,5 +7,4 @@ mod parallel_cycle_mid_recover; mod parallel_cycle_none_recover; #[cfg(disabled)] mod parallel_cycle_one_recover; -#[cfg(disabled)] mod signal; diff --git a/tests/parallel/parallel_cycle_all_recover.rs b/tests/parallel/parallel_cycle_all_recover.rs index fdddbf4..32dbbf6 100644 --- a/tests/parallel/parallel_cycle_all_recover.rs +++ b/tests/parallel/parallel_cycle_all_recover.rs @@ -2,6 +2,8 @@ //! See `../cycles.rs` for a complete listing of cycle tests, //! both intra and cross thread. +use salsa::Handle; + use crate::setup::Database; use crate::setup::Knobs; @@ -90,18 +92,18 @@ fn recover_b2(db: &dyn Db, _cycle: &salsa::Cycle, key: MyInput) -> i32 { #[test] fn execute() { - let db = Database::default(); - db.knobs().signal_on_will_block.set(3); + let db = Handle::new(Database::default()); + db.knobs().signal_on_will_block.store(3); - let input = MyInput::new(&db, 1); + let input = MyInput::new(&*db, 1); let thread_a = std::thread::spawn({ - let db = db.snapshot(); + let db = db.clone(); move || a1(&*db, input) }); let thread_b = std::thread::spawn({ - let db = db.snapshot(); + let db = db.clone(); move || b1(&*db, input) }); diff --git a/tests/parallel/setup.rs b/tests/parallel/setup.rs index e949d00..4830f3e 100644 --- a/tests/parallel/setup.rs +++ b/tests/parallel/setup.rs @@ -1,4 +1,4 @@ -use std::{cell::Cell, sync::Arc}; +use crossbeam::atomic::AtomicCell; use crate::signal::Signal; @@ -15,14 +15,14 @@ pub(crate) trait Knobs { /// Various "knobs" that can be used to customize how the queries /// behave on one specific thread. Note that this state is /// intentionally thread-local (apart from `signal`). -#[derive(Clone, Default)] +#[derive(Default)] pub(crate) struct KnobsStruct { /// A kind of flexible barrier used to coordinate execution across /// threads to ensure we reach various weird states. - pub(crate) signal: Arc, + pub(crate) signal: Signal, /// When this database is about to block, send a signal. - pub(crate) signal_on_will_block: Cell, + pub(crate) signal_on_will_block: AtomicCell, } #[salsa::db] @@ -36,7 +36,7 @@ pub(crate) struct Database { impl salsa::Database for Database { fn salsa_event(&self, event: salsa::Event) { if let salsa::EventKind::WillBlockOn { .. } = event.kind { - self.signal(self.knobs().signal_on_will_block.get()); + self.signal(self.knobs().signal_on_will_block.load()); } } }