rename freeze_revision to start_query

This commit is contained in:
Niko Matsakis 2018-10-19 05:36:06 -04:00
parent c327d08343
commit 2cf73b45c1
3 changed files with 7 additions and 20 deletions

View file

@ -209,7 +209,7 @@ where
) -> Result<StampedValue<Q::Value>, CycleDetected> { ) -> Result<StampedValue<Q::Value>, CycleDetected> {
let runtime = db.salsa_runtime(); let runtime = db.salsa_runtime();
let _read_lock = runtime.freeze_revision(); let _read_lock = runtime.start_query();
let revision_now = runtime.current_revision(); let revision_now = runtime.current_revision();

View file

@ -28,19 +28,6 @@ pub trait Database: plumbing::DatabaseStorageTypes {
/// Gives access to the underlying salsa runtime. /// Gives access to the underlying salsa runtime.
fn salsa_runtime(&self) -> &Runtime<Self>; fn salsa_runtime(&self) -> &Runtime<Self>;
/// Executes `op` while holding the "query lock". This guarantees
/// that all operations in `op` occur with one consistent database
/// revision: in particular, any attempts to `set` will block
/// until `op` returns (note that if `op` tries to invoke `set`,
/// you will get a deadlock).
///
/// (This is the same locking mechanism used by active derived
/// queries to ensure that they have a consistent view of the
/// database.)
fn with_frozen_revision<R>(&self, op: impl FnOnce() -> R) -> R {
self.salsa_runtime().with_frozen_revision(op)
}
/// Get access to extra methods pertaining to a given query, /// Get access to extra methods pertaining to a given query,
/// notably `set` (for inputs). /// notably `set` (for inputs).
#[allow(unused_variables)] #[allow(unused_variables)]

View file

@ -100,13 +100,13 @@ where
/// (However, if other threads invoke `increment_revision`, then /// (However, if other threads invoke `increment_revision`, then
/// the current revision may be considered cancelled, which can be /// the current revision may be considered cancelled, which can be
/// observed through `is_current_revision_canceled`.) /// observed through `is_current_revision_canceled`.)
pub(crate) fn freeze_revision(&self) -> Option<RevisionGuard<'_, DB>> { pub(crate) fn start_query(&self) -> Option<QueryGuard<'_, DB>> {
let mut local_state = self.local_state.borrow_mut(); let mut local_state = self.local_state.borrow_mut();
if !local_state.query_in_progress { if !local_state.query_in_progress {
local_state.query_in_progress = true; local_state.query_in_progress = true;
let guard = self.shared_state.query_lock.read(); let guard = self.shared_state.query_lock.read();
Some(RevisionGuard::new(self, guard)) Some(QueryGuard::new(self, guard))
} else { } else {
None None
} }
@ -116,7 +116,7 @@ where
/// `Database`. See the `Database` trait for more /// `Database`. See the `Database` trait for more
/// details. /// details.
pub fn with_frozen_revision<R>(&self, op: impl FnOnce() -> R) -> R { pub fn with_frozen_revision<R>(&self, op: impl FnOnce() -> R) -> R {
let _lock = self.freeze_revision(); let _lock = self.start_query();
op() op()
} }
@ -387,18 +387,18 @@ impl<DB: Database> Default for LocalState<DB> {
} }
} }
pub(crate) struct RevisionGuard<'db, DB: Database + 'db> { pub(crate) struct QueryGuard<'db, DB: Database + 'db> {
db: &'db Runtime<DB>, db: &'db Runtime<DB>,
lock: RwLockReadGuard<'db, ()>, lock: RwLockReadGuard<'db, ()>,
} }
impl<'db, DB: Database> RevisionGuard<'db, DB> { impl<'db, DB: Database> QueryGuard<'db, DB> {
fn new(db: &'db Runtime<DB>, lock: RwLockReadGuard<'db, ()>) -> Self { fn new(db: &'db Runtime<DB>, lock: RwLockReadGuard<'db, ()>) -> Self {
Self { db, lock } Self { db, lock }
} }
} }
impl<'db, DB: Database> Drop for RevisionGuard<'db, DB> { impl<'db, DB: Database> Drop for QueryGuard<'db, DB> {
fn drop(&mut self) { fn drop(&mut self) {
let mut local_state = self.db.local_state.borrow_mut(); let mut local_state = self.db.local_state.borrow_mut();
assert!(local_state.query_in_progress); assert!(local_state.query_in_progress);