remove use of upgradable reads from derived queries

This commit is contained in:
Niko Matsakis 2018-10-30 16:30:12 -04:00
parent 31789ec7ef
commit 2e4ff9a26e
2 changed files with 15 additions and 19 deletions

View file

@ -3,7 +3,6 @@
use crate::plumbing; use crate::plumbing;
use crate::plumbing::QueryStorageOps; use crate::plumbing::QueryStorageOps;
use crate::Database;
use crate::Query; use crate::Query;
use crate::QueryTable; use crate::QueryTable;
use std::iter::FromIterator; use std::iter::FromIterator;

View file

@ -13,7 +13,7 @@ use crate::runtime::StampedValue;
use crate::{Database, Event, EventKind, SweepStrategy}; use crate::{Database, Event, EventKind, SweepStrategy};
use log::{debug, info}; use log::{debug, info};
use parking_lot::Mutex; use parking_lot::Mutex;
use parking_lot::{RwLock, RwLockUpgradableReadGuard}; use parking_lot::RwLock;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -284,24 +284,21 @@ where
// Check with an upgradable read to see if there is a value // Check with an upgradable read to see if there is a value
// already. (This permits other readers but prevents anyone // already. (This permits other readers but prevents anyone
// else from running `read_upgrade` at the same time.) // else from running `read_upgrade` at the same time.)
let mut old_memo = match self.probe( //
db, // FIXME(Amanieu/parking_lot#101) -- we are using a write-lock
self.map.upgradable_read(), // and not an upgradable read here because upgradable reads
runtime, // can sometimes encounter deadlocks.
revision_now, let mut old_memo =
descriptor, match self.probe(db, self.map.write(), runtime, revision_now, descriptor, key) {
key, ProbeState::UpToDate(v) => return v,
) { ProbeState::StaleOrAbsent(mut map) => {
ProbeState::UpToDate(v) => return v, match map.insert(key.clone(), QueryState::in_progress(runtime.id())) {
ProbeState::StaleOrAbsent(map) => { Some(QueryState::Memoized(old_memo)) => Some(old_memo),
let mut map = RwLockUpgradableReadGuard::upgrade(map); Some(QueryState::InProgress { .. }) => unreachable!(),
match map.insert(key.clone(), QueryState::in_progress(runtime.id())) { None => None,
Some(QueryState::Memoized(old_memo)) => Some(old_memo), }
Some(QueryState::InProgress { .. }) => unreachable!(),
None => None,
} }
} };
};
let panic_guard = PanicGuard::new(&self.map, key, descriptor, runtime); let panic_guard = PanicGuard::new(&self.map, key, descriptor, runtime);