Skip to content

Commit 678f51a

Browse files
authored
Short-circuit block-on if same thread (#862)
* Short-circuit `block_on` if same thread * Avoid acquiring the lock
1 parent 18dc594 commit 678f51a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/runtime.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,13 @@ impl Runtime {
172172
other_id: ThreadId,
173173
query_mutex_guard: QueryMutexGuard,
174174
) -> BlockResult {
175-
let dg = self.dependency_graph.lock();
176175
let thread_id = thread::current().id();
176+
// Cycle in the same thread.
177+
if thread_id == other_id {
178+
return BlockResult::Cycle;
179+
}
180+
181+
let dg = self.dependency_graph.lock();
177182

178183
if dg.depends_on(other_id, thread_id) {
179184
return BlockResult::Cycle;

0 commit comments

Comments
 (0)