Skip to content

Commit

Permalink
Always use parking_lot's RwLock, even without parallel compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Aug 1, 2023
1 parent b321edd commit 3eb5733
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions compiler/rustc_data_structures/src/sync/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,23 @@ impl<I: Idx, T: Copy> AppendOnlyIndexVec<I, T> {

#[derive(Default)]
pub struct AppendOnlyVec<T: Copy> {
#[cfg(not(parallel_compiler))]
vec: elsa::vec::FrozenVec<T>,
#[cfg(parallel_compiler)]
vec: elsa::sync::LockFreeFrozenVec<T>,
vec: parking_lot::RwLock<Vec<T>>,
}

impl<T: Copy> AppendOnlyVec<T> {
pub fn new() -> Self {
Self {
#[cfg(not(parallel_compiler))]
vec: elsa::vec::FrozenVec::new(),
#[cfg(parallel_compiler)]
vec: elsa::sync::LockFreeFrozenVec::new(),
}
Self { vec: Default::default() }
}

pub fn push(&self, val: T) -> usize {
#[cfg(not(parallel_compiler))]
let i = self.vec.len();
#[cfg(not(parallel_compiler))]
self.vec.push(val);
#[cfg(parallel_compiler)]
let i = self.vec.push(val);
i
let mut v = self.vec.write();
let n = v.len();
v.push(val);
n
}

pub fn get(&self, i: usize) -> Option<T> {
#[cfg(not(parallel_compiler))]
return self.vec.get_copy(i);
#[cfg(parallel_compiler)]
return self.vec.get(i);
self.vec.read().get(i).copied()
}

pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ {
Expand Down

0 comments on commit 3eb5733

Please sign in to comment.