Rollup merge of #114283 - oli-obk:parkin_lot_rwlock, r=SparrowLii

Use parking lot's rwlock even without parallel-rustc

Considering that this doesn't affect perf, I think we should use the simplest solution.
This commit is contained in:
Matthias Krüger 2023-08-01 17:39:10 +02:00 committed by GitHub
commit b38718090e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,37 +43,23 @@ impl<I: Idx, T: Copy> AppendOnlyIndexVec<I, T> {
#[derive(Default)] #[derive(Default)]
pub struct AppendOnlyVec<T: Copy> { pub struct AppendOnlyVec<T: Copy> {
#[cfg(not(parallel_compiler))] vec: parking_lot::RwLock<Vec<T>>,
vec: elsa::vec::FrozenVec<T>,
#[cfg(parallel_compiler)]
vec: elsa::sync::LockFreeFrozenVec<T>,
} }
impl<T: Copy> AppendOnlyVec<T> { impl<T: Copy> AppendOnlyVec<T> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self { vec: Default::default() }
#[cfg(not(parallel_compiler))]
vec: elsa::vec::FrozenVec::new(),
#[cfg(parallel_compiler)]
vec: elsa::sync::LockFreeFrozenVec::new(),
}
} }
pub fn push(&self, val: T) -> usize { pub fn push(&self, val: T) -> usize {
#[cfg(not(parallel_compiler))] let mut v = self.vec.write();
let i = self.vec.len(); let n = v.len();
#[cfg(not(parallel_compiler))] v.push(val);
self.vec.push(val); n
#[cfg(parallel_compiler)]
let i = self.vec.push(val);
i
} }
pub fn get(&self, i: usize) -> Option<T> { pub fn get(&self, i: usize) -> Option<T> {
#[cfg(not(parallel_compiler))] self.vec.read().get(i).copied()
return self.vec.get_copy(i);
#[cfg(parallel_compiler)]
return self.vec.get(i);
} }
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ { pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ {