Skip to content

Commit

Permalink
In HP, only free every 32rd call to free_from_queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Hafskjold Thoresen committed Dec 12, 2017
1 parent 7b22f79 commit 23dc7ca
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/hp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,33 @@ where

#[cfg(not(feature = "hp-wait"))]
fn free_from_queue() {
const N: usize = 3;
for _ in 0..N {
if let Some(garbage) = HAZARD_QUEUE.pop_hp_fn(|h| {
h.spin();
unsafe {
h.into_owned();
}
})
{
if HazardPtr::<()>::scan_addr(garbage.address()) {
// used
HAZARD_QUEUE.push(garbage);
const N: usize = 32;
thread_local! {
static COUNTER: RefCell<usize> = { RefCell::new(0) }
}
let c = COUNTER.with(|c| {
let c = &mut *c.borrow_mut();
*c += 1;
*c
});
if c % N == 0 {
for _ in 0..N {
if let Some(garbage) = HAZARD_QUEUE.pop_hp_fn(|h| {
h.spin();
unsafe {
h.into_owned();
}
})
{
if HazardPtr::<()>::scan_addr(garbage.address()) {
// used
HAZARD_QUEUE.push(garbage);
} else {
drop(garbage);
}
} else {
drop(garbage);
return;
}
} else {
return;
}
}
}
Expand Down

0 comments on commit 23dc7ca

Please sign in to comment.