Skip to content

Commit

Permalink
Merge pull request #166 from xacrimon/joel/parking-lot
Browse files Browse the repository at this point in the history
Use parking_lot for locks
  • Loading branch information
xacrimon authored Dec 12, 2021
2 parents 45058db + 38e7703 commit 0b38180
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 587 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ raw-api = []

[dependencies]
num_cpus = "1.13.0"
serde = { version = "1.0.118", optional = true, features = ["derive"] }
parking_lot = { version = "0.11.2", features = ["send_guard"] }
serde = { version = "1.0.131", optional = true, features = ["derive"] }
cfg-if = "1.0.0"
rayon = { version = "1.5.0", optional = true }
rayon = { version = "1.5.1", optional = true }

[package.metadata.docs.rs]
features = ["rayon", "raw-api", "serde"]
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::mapref::multiple::{RefMulti, RefMutMulti};
use super::util;
use crate::lock::{RwLockReadGuard, RwLockWriteGuard};
use crate::t::Map;
use crate::util::SharedValue;
use crate::{DashMap, HashMap};
use core::hash::{BuildHasher, Hash};
use core::mem;
use parking_lot::{RwLockReadGuard, RwLockWriteGuard};
use std::collections::hash_map;
use std::collections::hash_map::RandomState;
use std::sync::Arc;
Expand Down
20 changes: 4 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub mod iter;
pub mod iter_set;
pub mod lock;
pub mod mapref;
mod read_only;
#[cfg(feature = "serde")]
Expand All @@ -25,10 +24,10 @@ use core::hash::{BuildHasher, Hash, Hasher};
use core::iter::FromIterator;
use core::ops::{BitAnd, BitOr, Shl, Shr, Sub};
use iter::{Iter, IterMut, OwningIter};
use lock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use mapref::entry::{Entry, OccupiedEntry, VacantEntry};
use mapref::multiple::RefMulti;
use mapref::one::{Ref, RefMut};
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
pub use read_only::ReadOnlyView;
pub use set::DashSet;
use std::collections::hash_map::RandomState;
Expand Down Expand Up @@ -653,7 +652,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S>
unsafe fn _get_read_shard(&'a self, i: usize) -> &'a HashMap<K, V, S> {
debug_assert!(i < self.shards.len());

self.shards.get_unchecked(i).get()
&*self.shards.get_unchecked(i).data_ptr()
}

unsafe fn _yield_read_shard(&'a self, i: usize) -> RwLockReadGuard<'a, HashMap<K, V, S>> {
Expand Down Expand Up @@ -1082,24 +1081,13 @@ mod tests {
dm.insert(9, "Potato".to_string());
dm.insert(12, "Chicken".to_string());

let potato_vegetableness = dm.view(&9, |_, v| {
let is_vegetable = vegetables.contains(v);

is_vegetable
});

let potato_vegetableness = dm.view(&9, |_, v| vegetables.contains(v));
assert_eq!(potato_vegetableness, Some(true));

let chicken_vegetableness = dm.view(&12, |_, v| {
let is_vegetable = vegetables.contains(v);

is_vegetable
});

let chicken_vegetableness = dm.view(&12, |_, v| vegetables.contains(v));
assert_eq!(chicken_vegetableness, Some(false));

let not_in_map = dm.view(&30, |_k, _v| false);

assert_eq!(not_in_map, None);
}
}
Loading

0 comments on commit 0b38180

Please sign in to comment.