diff --git a/crates/victory-gpu/src/watch.rs b/crates/victory-gpu/src/watch.rs index 1e63f3431..ffba04f8b 100644 --- a/crates/victory-gpu/src/watch.rs +++ b/crates/victory-gpu/src/watch.rs @@ -1989,33 +1989,34 @@ fn guard(start: usize, end: usize) -> Option> { // runtime's. Windows is asked with the lock not held (the range is, no // other thread asks about it: `ASKING`); what the runtime tells meanwhile // takes the block out of the set, and it is looked at as any other. - let unsure: Vec = { - let g = guards_timed(); - if g.clean.range(first..last).count() == last - first && !BESIDE.any(first, last) && !unsettled(first, last) { - // Nothing written, mapped or new since the range was last taken. - #[cfg(feature = "diagnostics")] - tally(3, 1); - return Some(Vec::new()); - } - g.absent.range(first..last).filter(|block| !g.held.contains(*block)).collect() - }; + let mut g = guards_timed(); + if g.clean.range(first..last).count() == last - first && !BESIDE.any(first, last) && !unsettled(first, last) { + // Nothing written, mapped or new since the range was last taken. + #[cfg(feature = "diagnostics")] + tally(3, 1); + return Some(Vec::new()); + } + let unsure: Vec<_> = g.absent.range(first..last).filter(|block| !g.held.contains(*block)).collect(); let mut came: Vec<(usize, bool)> = Vec::new(); - let mut uncommitted_until = first; - for block in unsure { - // One question for the blocks of a region. - if block >= uncommitted_until { - uncommitted_until = uncommitted_end(block); - #[cfg(feature = "diagnostics")] - tally(9, 1); - } - if block >= uncommitted_until { - // The hole may have been given up, and its address be the - // title's heap's, or code's, now: not ours to guard. - came.push((block, is_view(block * BLOCK, (block + 1) * BLOCK))); + if !unsure.is_empty() || !crate::asked_for!("VICTORY_KEEP_GUARD_LOCK") { + drop(g); + let mut uncommitted_until = first; + for block in unsure { + // One question for the blocks of a region. + if block >= uncommitted_until { + uncommitted_until = uncommitted_end(block); + #[cfg(feature = "diagnostics")] + tally(9, 1); + } + if block >= uncommitted_until { + // The hole may have been given up, and its address be the + // title's heap's, or code's, now: not ours to guard. + came.push((block, is_view(block * BLOCK, (block + 1) * BLOCK))); + } } + g = guards_timed(); } let rest = rest(); - let mut g = guards_timed(); #[cfg(feature = "diagnostics")] tally(4, 1); for &(block, view) in &came {