Skip to content

Commit

Permalink
Automatically clear the cancellation flag when cancellation completes
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Feb 17, 2025
1 parent 534a599 commit 1cca261
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion components/salsa-macro-rules/src/setup_tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ macro_rules! setup_tracked_fn {

pub fn fn_ingredient_mut(db: &mut dyn $Db) -> &mut $zalsa::function::IngredientImpl<Self> {
let zalsa_mut = db.zalsa_mut();
zalsa_mut.reset_cancellation_flag();
let index = zalsa_mut.add_or_lookup_jar_by_type(&$Configuration);
let (ingredient, _) = zalsa_mut.lookup_ingredient_mut(index);
ingredient.assert_type_mut::<$zalsa::function::IngredientImpl<Self>>()
Expand Down
1 change: 0 additions & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl Runtime {
let r_old = self.current_revision();
let r_new = r_old.next();
self.revisions[0] = r_new;
self.reset_cancellation_flag();
r_new
}

Expand Down
9 changes: 6 additions & 3 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ impl<Db: Database> Storage<Db> {
///
/// This could deadlock if there is a single worker with two handles to the
/// same database!
///
/// Needs to be paired with a call to `reset_cancellation_flag`.
fn cancel_others(&self, db: &Db) {
self.handle.zalsa_impl.set_cancellation_flag();

Expand All @@ -140,9 +142,10 @@ unsafe impl<T: HasStorage> ZalsaDatabase for T {

let storage = self.storage_mut();
// The ref count on the `Arc` should now be 1
let zalsa_mut = Arc::get_mut(&mut storage.handle.zalsa_impl).unwrap();
zalsa_mut.new_revision();
zalsa_mut
let zalsa = Arc::get_mut(&mut storage.handle.zalsa_impl).unwrap();
// cancellation is done, so reset the flag
zalsa.reset_cancellation_flag();
zalsa
}

fn zalsa_local(&self) -> &ZalsaLocal {
Expand Down
6 changes: 1 addition & 5 deletions src/zalsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub unsafe trait ZalsaDatabase: Any {
///
/// **WARNING:** Triggers cancellation to other database handles.
/// This can lead to deadlock!
///
/// Note that this needs to be paired with a call to `Zalsa::new_revision` or `Zalsa::clear_cancellation_flag`.
#[doc(hidden)]
fn zalsa_mut(&mut self) -> &mut Zalsa;

Expand Down Expand Up @@ -266,9 +264,7 @@ impl Zalsa {
self.runtime.load_cancellation_flag()
}

/// **NOT SEMVER STABLE**
#[doc(hidden)]
pub fn reset_cancellation_flag(&mut self) {
pub(crate) fn reset_cancellation_flag(&mut self) {
self.runtime.reset_cancellation_flag();
}

Expand Down

0 comments on commit 1cca261

Please sign in to comment.