mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
Merge pull request #230 from lnicola/upgradable-lock
Remove workaround for parking_lot#101
This commit is contained in:
commit
5078c9b22d
2 changed files with 8 additions and 7 deletions
|
@ -11,6 +11,7 @@ readme = "README.md"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossbeam = "0.7.1"
|
crossbeam = "0.7.1"
|
||||||
indexmap = "1.0.1"
|
indexmap = "1.0.1"
|
||||||
|
lock_api = "0.4"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
parking_lot = "0.11.0"
|
parking_lot = "0.11.0"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::runtime::StampedValue;
|
||||||
use crate::{CycleError, Database, DiscardIf, DiscardWhat, Event, EventKind, SweepStrategy};
|
use crate::{CycleError, Database, DiscardIf, DiscardWhat, Event, EventKind, SweepStrategy};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::{RawRwLock, RwLock};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -165,13 +165,13 @@ 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 old_memo = match self.probe(db, self.state.upgradable_read(), runtime, revision_now) {
|
||||||
// FIXME(Amanieu/parking_lot#101) -- we are using a write-lock
|
|
||||||
// and not an upgradable read here because upgradable reads
|
|
||||||
// can sometimes encounter deadlocks.
|
|
||||||
let old_memo = match self.probe(db, self.state.write(), runtime, revision_now) {
|
|
||||||
ProbeState::UpToDate(v) => return v,
|
ProbeState::UpToDate(v) => return v,
|
||||||
ProbeState::StaleOrAbsent(mut state) => {
|
ProbeState::StaleOrAbsent(state) => {
|
||||||
|
type RwLockUpgradableReadGuard<'a, T> =
|
||||||
|
lock_api::RwLockUpgradableReadGuard<'a, RawRwLock, T>;
|
||||||
|
|
||||||
|
let mut state = RwLockUpgradableReadGuard::upgrade(state);
|
||||||
match std::mem::replace(&mut *state, QueryState::in_progress(runtime.id())) {
|
match std::mem::replace(&mut *state, QueryState::in_progress(runtime.id())) {
|
||||||
QueryState::Memoized(old_memo) => Some(old_memo),
|
QueryState::Memoized(old_memo) => Some(old_memo),
|
||||||
QueryState::InProgress { .. } => unreachable!(),
|
QueryState::InProgress { .. } => unreachable!(),
|
||||||
|
|
Loading…
Reference in a new issue