Skip to content

Commit

Permalink
Remove parking_lot dependency
Browse files Browse the repository at this point in the history
std::sync::Mutex now has comparable performance
  • Loading branch information
nicoburns committed Sep 10, 2024
1 parent 471ca0d commit dcd06c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ once_cell = "1.10.0"
serde = { version = "1", optional = true }
phf_shared = "0.11"
new_debug_unreachable = "1.0.2"
parking_lot = "0.12"

[[test]]
name = "small-stack"
Expand Down
6 changes: 3 additions & 3 deletions src/dynamic_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// except according to those terms.

use once_cell::sync::Lazy;
use parking_lot::Mutex;
use std::borrow::Cow;
use std::mem;
use std::ptr::NonNull;
use std::sync::atomic::AtomicIsize;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Mutex;

const NB_BUCKETS: usize = 1 << 12; // 4096
const BUCKET_MASK: u32 = (1 << 12) - 1;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub(crate) static DYNAMIC_SET: Lazy<Set> = Lazy::new(|| {
impl Set {
pub(crate) fn insert(&self, string: Cow<str>, hash: u32) -> NonNull<Entry> {
let bucket_index = (hash & BUCKET_MASK) as usize;
let mut linked_list = self.buckets[bucket_index].lock();
let mut linked_list = self.buckets[bucket_index].lock().unwrap();

{
let mut ptr: Option<&mut Box<Entry>> = linked_list.as_mut();
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Set {
let value: &Entry = unsafe { &*ptr };
let bucket_index = (value.hash & BUCKET_MASK) as usize;

let mut linked_list = self.buckets[bucket_index].lock();
let mut linked_list = self.buckets[bucket_index].lock().unwrap();
debug_assert!(value.ref_count.load(SeqCst) == 0);
let mut current: &mut Option<Box<Entry>> = &mut linked_list;

Expand Down

0 comments on commit dcd06c1

Please sign in to comment.