Short-circuit block-on if same thread (#862)
Some checks failed
Test / Test (push) Has been cancelled
Book / Book (push) Has been cancelled
Release-plz / Release-plz release (push) Has been cancelled
Release-plz / Release-plz PR (push) Has been cancelled
Test / Miri (push) Has been cancelled
Test / Benchmarks (push) Has been cancelled
Book / Deploy (push) Has been cancelled

* Short-circuit `block_on` if same thread

* Avoid acquiring the lock
This commit is contained in:
Micha Reiser 2025-05-22 11:26:17 +02:00 committed by GitHub
parent 18dc594dea
commit 678f51a745
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -172,8 +172,13 @@ impl Runtime {
other_id: ThreadId,
query_mutex_guard: QueryMutexGuard,
) -> BlockResult {
let dg = self.dependency_graph.lock();
let thread_id = thread::current().id();
// Cycle in the same thread.
if thread_id == other_id {
return BlockResult::Cycle;
}
let dg = self.dependency_graph.lock();
if dg.depends_on(other_id, thread_id) {
return BlockResult::Cycle;