Skip to content

Commit

Permalink
Drop lock (#23765)
Browse files Browse the repository at this point in the history
  • Loading branch information
carllin authored Mar 21, 2022
1 parent dd69f3b commit f34434f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions runtime/src/secondary_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,20 @@ impl<SecondaryIndexEntryType: SecondaryIndexEntry + Default + Sync + Send>
pubkeys_map.insert_if_not_exists(inner_key, &self.stats.num_inner_keys);
}

let outer_keys = self.reverse_index.get(inner_key).unwrap_or_else(|| {
self.reverse_index
.entry(*inner_key)
.or_insert(RwLock::new(Vec::with_capacity(1)))
.downgrade()
});

let should_insert = !outer_keys.read().unwrap().contains(key);
if should_insert {
let mut w_outer_keys = outer_keys.write().unwrap();
if !w_outer_keys.contains(key) {
w_outer_keys.push(*key);
{
let outer_keys = self.reverse_index.get(inner_key).unwrap_or_else(|| {
self.reverse_index
.entry(*inner_key)
.or_insert(RwLock::new(Vec::with_capacity(1)))
.downgrade()
});

let should_insert = !outer_keys.read().unwrap().contains(key);
if should_insert {
let mut w_outer_keys = outer_keys.write().unwrap();
if !w_outer_keys.contains(key) {
w_outer_keys.push(*key);
}
}
}

Expand Down

0 comments on commit f34434f

Please sign in to comment.