Skip to content

Commit

Permalink
Use incrementing index instead of ptr address as seed
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed May 30, 2019
1 parent 4d78285 commit 757a640
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions core/src/parking_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ impl HashTable {

let now = Instant::now();
let mut entries = Vec::with_capacity(new_size);
for _ in 0..new_size {
entries.push(Bucket::new(now));
for i in 0..new_size {
// We must ensure the seed is not zero
entries.push(Bucket::new(now, i as u32 + 1));
}

Box::new(HashTable { entries: entries.into_boxed_slice(), hash_bits, _prev: prev })
Expand All @@ -65,12 +66,12 @@ struct Bucket {

impl Bucket {
#[inline]
pub fn new(timeout: Instant) -> Self {
pub fn new(timeout: Instant, seed: u32) -> Self {
Self {
mutex: WordLock::INIT,
queue_head: Cell::new(ptr::null()),
queue_tail: Cell::new(ptr::null()),
fair_timeout: UnsafeCell::new(FairTimeout::new(timeout)),
fair_timeout: UnsafeCell::new(FairTimeout::new(timeout, seed)),
}
}
}
Expand All @@ -85,8 +86,8 @@ struct FairTimeout {

impl FairTimeout {
#[inline]
fn new(timeout: Instant) -> FairTimeout {
FairTimeout { timeout, seed: &timeout as *const _ as usize as u32 }
fn new(timeout: Instant, seed: u32) -> FairTimeout {
FairTimeout { timeout, seed }
}

// Determine whether we should force a fair unlock, and update the timeout
Expand Down

0 comments on commit 757a640

Please sign in to comment.