Skip to content

Commit

Permalink
bugfix: Fix a bug that MIRI spotted
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Apr 14, 2024
1 parent 36424f4 commit 0d8f8e8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/linked_list/no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ impl<T> Link<T> {
let old_state = self.state.fetch_or(REGISTERING, Ordering::SeqCst);
if old_state & NOTIFIED != 0 {
// poll() somehow missed the notification. Wake the event loop and try again.
let _guard = CallOnDrop(|| {
self.state.fetch_and(!REGISTERING, Ordering::SeqCst);
});
waker.wake_by_ref();
return;
}
Expand Down Expand Up @@ -624,7 +627,7 @@ impl<T> Slots<T> {
}
};

unsafe { slice::from_raw_parts_mut(ptr.as_ptr(), size) }
unsafe { slice::from_raw_parts(ptr.as_ptr(), size) }
}
}

Expand Down Expand Up @@ -744,6 +747,11 @@ mod tests {

type HashSet<K> = hashbrown::HashSet<K, ahash::RandomState>;

#[cfg(not(miri))]
const MAX: usize = 0xFFFF;
#[cfg(miri)]
const MAX: usize = 0xFF;

#[test]
fn lock() {
let lock = Lock::new(());
Expand All @@ -760,8 +768,7 @@ mod tests {
let mut seen_ptrs: HashSet<usize> = HashSet::with_hasher(ahash::RandomState::default());

// Don't exhaust our memory; only do this many.
let count = 0xFFFF;
for i in 1..count {
for i in 1..MAX {
let not_yet_seen = seen_ptrs.insert(slots.get(i) as *const Link<()> as usize);
assert!(not_yet_seen);
}
Expand All @@ -772,7 +779,7 @@ mod tests {
let index = Indexes::new();
let mut last = 0;

for _ in 0..0xFFFF {
for _ in 0..MAX {
let val = index.alloc();
assert_eq!(val, last + 1);
last = val;
Expand Down

0 comments on commit 0d8f8e8

Please sign in to comment.