From 1dca6c1048b591256167f31c68912a165336675a Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sun, 6 Nov 2022 13:06:50 +0100 Subject: [PATCH] runtime: fix `unsync_load` on atomic types --- tokio/src/loom/std/atomic_u16.rs | 2 +- tokio/src/loom/std/atomic_u32.rs | 2 +- tokio/src/loom/std/atomic_usize.rs | 2 +- tokio/src/runtime/tests/queue.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/src/loom/std/atomic_u16.rs b/tokio/src/loom/std/atomic_u16.rs index b3103dd4657..c9e105c1934 100644 --- a/tokio/src/loom/std/atomic_u16.rs +++ b/tokio/src/loom/std/atomic_u16.rs @@ -23,7 +23,7 @@ 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 { - *(*self.inner.get()).get_mut() + core::ptr::read(self.inner.get() as *const u16) } } diff --git a/tokio/src/loom/std/atomic_u32.rs b/tokio/src/loom/std/atomic_u32.rs index 32dd85d096b..ee0d2d38050 100644 --- a/tokio/src/loom/std/atomic_u32.rs +++ b/tokio/src/loom/std/atomic_u32.rs @@ -23,7 +23,7 @@ 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 { - *(*self.inner.get()).get_mut() + core::ptr::read(self.inner.get() as *const u32) } } diff --git a/tokio/src/loom/std/atomic_usize.rs b/tokio/src/loom/std/atomic_usize.rs index fa918f1de1a..c5503a2c122 100644 --- a/tokio/src/loom/std/atomic_usize.rs +++ b/tokio/src/loom/std/atomic_usize.rs @@ -23,7 +23,7 @@ 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 { - *(*self.inner.get()).get_mut() + core::ptr::read(self.inner.get() as *const usize) } pub(crate) fn with_mut(&mut self, f: impl FnOnce(&mut usize) -> R) -> R { diff --git a/tokio/src/runtime/tests/queue.rs b/tokio/src/runtime/tests/queue.rs index ed9fd49cca8..68d2e892ea3 100644 --- a/tokio/src/runtime/tests/queue.rs +++ b/tokio/src/runtime/tests/queue.rs @@ -111,7 +111,7 @@ const fn normal_or_miri(normal: usize, miri: usize) -> usize { #[test] fn stress1() { - const NUM_ITER: usize = 1; + const NUM_ITER: usize = 5; const NUM_STEAL: usize = normal_or_miri(1_000, 10); const NUM_LOCAL: usize = normal_or_miri(1_000, 10); const NUM_PUSH: usize = normal_or_miri(500, 10);