Optimize lock_shards

This commit is contained in:
John Kåre Alsaker 2023-08-17 11:07:50 +02:00
parent b74cb78d63
commit f458b112f8
4 changed files with 42 additions and 34 deletions

View file

@ -70,8 +70,7 @@ where
}
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
let shards = self.cache.lock_shards();
for shard in shards.iter() {
for shard in self.cache.lock_shards() {
for (k, v) in shard.iter() {
f(k, &v.0, v.1);
}
@ -160,8 +159,7 @@ where
}
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
let shards = self.cache.lock_shards();
for shard in shards.iter() {
for shard in self.cache.lock_shards() {
for (k, v) in shard.iter_enumerated() {
if let Some(v) = v {
f(&k, &v.0, v.1);

View file

@ -50,8 +50,7 @@ where
D: DepKind,
{
pub fn all_inactive(&self) -> bool {
let shards = self.active.lock_shards();
shards.iter().all(|shard| shard.is_empty())
self.active.lock_shards().all(|shard| shard.is_empty())
}
pub fn try_collect_active_jobs<Qcx: Copy>(
@ -64,9 +63,8 @@ where
// We use try_lock_shards here since we are called from the
// deadlock handler, and this shouldn't be locked.
let shards = self.active.try_lock_shards()?;
for shard in shards.iter() {
for (k, v) in shard.iter() {
for shard in self.active.try_lock_shards() {
for (k, v) in shard?.iter() {
if let QueryResult::Started(ref job) = *v {
active.push((*k, job.clone()));
}