chore: use relaxed load for unsync_load on miri (#6179)

This commit is contained in:
Alice Ryhl
2023-12-08 09:48:15 +01:00
committed by GitHub
parent d561b5850a
commit 48c0e6283f
3 changed files with 15 additions and 3 deletions
+5 -1
View File
@@ -23,7 +23,11 @@ impl AtomicU16 {
/// All mutations must have happened before the unsynchronized load.
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> u16 {
core::ptr::read(self.inner.get() as *const u16)
// See <https://github.com/tokio-rs/tokio/issues/6155>
#[cfg(miri)]
return self.load(std::sync::atomic::Ordering::Relaxed);
#[cfg(not(miri))]
return core::ptr::read(self.inner.get() as *const u16);
}
}
+5 -1
View File
@@ -23,7 +23,11 @@ impl AtomicU32 {
/// All mutations must have happened before the unsynchronized load.
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> u32 {
core::ptr::read(self.inner.get() as *const u32)
// See <https://github.com/tokio-rs/tokio/issues/6155>
#[cfg(miri)]
return self.load(std::sync::atomic::Ordering::Relaxed);
#[cfg(not(miri))]
return core::ptr::read(self.inner.get() as *const u32);
}
}
+5 -1
View File
@@ -23,7 +23,11 @@ impl AtomicUsize {
/// All mutations must have happened before the unsynchronized load.
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> usize {
core::ptr::read(self.inner.get() as *const usize)
// See <https://github.com/tokio-rs/tokio/issues/6155>
#[cfg(miri)]
return self.load(std::sync::atomic::Ordering::Relaxed);
#[cfg(not(miri))]
return core::ptr::read(self.inner.get() as *const usize);
}
pub(crate) fn with_mut<R>(&mut self, f: impl FnOnce(&mut usize) -> R) -> R {