Skip to content

Commit

Permalink
Don't run pause/yield in the last iteration of wait_for_readers
Browse files Browse the repository at this point in the history
Because it needlessly slows things down when everything is already
prepared.

+ Disable the yields/pauses on miri, as they are not supported.

Closes #30.
  • Loading branch information
vorner committed Apr 17, 2020
1 parent 79acd3f commit 09cb648
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ impl<T: RefCnt, S: LockStorage> ArcSwapAny<T, S> {
fn wait_for_readers(&self, old: *const T::Base) {
let mut seen_group = [false; GEN_CNT];
let mut iter = 0usize;
while !seen_group.iter().all(|seen| *seen) {

loop {
// Note that we don't need the snapshot to be consistent. We just need to see both
// halves being zero, not necessarily at the same time.
let gen = self.lock_storage.gen_idx().load(Ordering::Relaxed);
Expand All @@ -1021,11 +1022,18 @@ impl<T: RefCnt, S: LockStorage> ArcSwapAny<T, S> {
for i in 0..GEN_CNT {
seen_group[i] = seen_group[i] || (groups[i] == 0);
}

if seen_group.iter().all(|seen| *seen) {
break;
}

iter = iter.wrapping_add(1);
if iter % YIELD_EVERY == 0 {
thread::yield_now();
} else {
atomic::spin_loop_hint();
if cfg!(not(miri)) {
if iter % YIELD_EVERY == 0 {
thread::yield_now();
} else {
atomic::spin_loop_hint();
}
}
}
Debt::pay_all::<T>(old);
Expand Down

0 comments on commit 09cb648

Please sign in to comment.