From 93ee78e73f7e5a32e5d7e9a05e512c4f9cc3a7bf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 11 Nov 2021 05:39:44 -0500 Subject: [PATCH] factor out a helper to unblock a given runtime --- src/runtime.rs | 2 +- src/runtime/dependency_graph.rs | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index 3d040f53..0e691d42 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -423,7 +423,7 @@ impl Runtime { self.shared_state .dependency_graph .lock() - .unblock_dependents_of(database_key, self.id(), wait_result); + .unblock_runtimes_blocked_on(database_key, wait_result); } } diff --git a/src/runtime/dependency_graph.rs b/src/runtime/dependency_graph.rs index 457f7a0d..af204ab6 100644 --- a/src/runtime/dependency_graph.rs +++ b/src/runtime/dependency_graph.rs @@ -187,10 +187,9 @@ impl DependencyGraph { /// Invoked when runtime `to_id` completes executing /// `database_key`. - pub(super) fn unblock_dependents_of( + pub(super) fn unblock_runtimes_blocked_on( &mut self, database_key: DatabaseKeyIndex, - to_id: RuntimeId, wait_result: WaitResult, ) { let dependents = self @@ -199,13 +198,19 @@ impl DependencyGraph { .unwrap_or_default(); for from_id in dependents { - let edge = self.edges.remove(&from_id).expect("no edge for dependent"); - assert_eq!(to_id, edge.blocked_on_id); - self.wait_results.insert(from_id, (edge.stack, wait_result)); - - // Now that we have inserted the `wait_results`, - // notify the thread. - edge.condvar.notify_one(); + self.unblock_runtime(from_id, wait_result); } } + + /// Unblock the runtime with the given id with the given wait-result. + /// This will cause it resume execution (though it will have to grab + /// the lock on this data structure first, to recover the wait result). + fn unblock_runtime(&mut self, id: RuntimeId, wait_result: WaitResult) { + let edge = self.edges.remove(&id).expect("not blocked"); + self.wait_results.insert(id, (edge.stack, wait_result)); + + // Now that we have inserted the `wait_results`, + // notify the thread. + edge.condvar.notify_one(); + } }