Skip to content

Commit

Permalink
Merge branch 'miri'
Browse files Browse the repository at this point in the history
  • Loading branch information
vorner committed Apr 21, 2020
2 parents 8a93bb5 + 09cb648 commit 005ec45
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 005ec45

Please sign in to comment.