From e6881e4abbc004358c60a5e46ca59db3a5652a56 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 2 Jun 2019 05:56:54 -0400 Subject: [PATCH] Drop nodes mutex before shuffling result --- src/datastore.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/datastore.rs b/src/datastore.rs index fd776c7..e7bf99a 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -492,15 +492,17 @@ impl Store { let mut res = Vec::with_capacity(results); let cur_time = Instant::now(); - let mut nodes = self.nodes.write().unwrap(); - for (idx, state_nodes) in nodes.state_next_scan.iter_mut().enumerate() { - let cmp_time = cur_time - Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::from_num(idx as u8).unwrap()))); - let split_point = cmp::min(cmp::min(results - res.len(), results - (per_bucket_results * (AddressState::get_count() as usize - idx))), - state_nodes.binary_search_by(|a| a.0.cmp(&cmp_time)).unwrap_or_else(|idx| idx)); - let mut new_nodes = state_nodes.split_off(split_point); - mem::swap(&mut new_nodes, state_nodes); - for (_, node) in new_nodes.drain(..) { - res.push(node); + { + let mut nodes = self.nodes.write().unwrap(); + for (idx, state_nodes) in nodes.state_next_scan.iter_mut().enumerate() { + let cmp_time = cur_time - Duration::from_secs(self.get_u64(U64Setting::RescanInterval(AddressState::from_num(idx as u8).unwrap()))); + let split_point = cmp::min(cmp::min(results - res.len(), results - (per_bucket_results * (AddressState::get_count() as usize - idx))), + state_nodes.binary_search_by(|a| a.0.cmp(&cmp_time)).unwrap_or_else(|idx| idx)); + let mut new_nodes = state_nodes.split_off(split_point); + mem::swap(&mut new_nodes, state_nodes); + for (_, node) in new_nodes.drain(..) { + res.push(node); + } } } res.shuffle(&mut thread_rng()); -- 2.39.5