Skip to content

Commit

Permalink
chore: use relaxed load for unsync_load (#6203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Dec 8, 2023
1 parent c9273f1 commit 1968565
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
5 changes: 1 addition & 4 deletions tokio/src/loom/std/atomic_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ impl AtomicU16 {
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> 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);
self.load(std::sync::atomic::Ordering::Relaxed)
}
}

Expand Down
5 changes: 1 addition & 4 deletions tokio/src/loom/std/atomic_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ impl AtomicU32 {
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> 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);
self.load(std::sync::atomic::Ordering::Relaxed)
}
}

Expand Down
5 changes: 1 addition & 4 deletions tokio/src/loom/std/atomic_usize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ impl AtomicUsize {
/// Additionally, there must be no concurrent mutations.
pub(crate) unsafe fn unsync_load(&self) -> 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);
self.load(std::sync::atomic::Ordering::Relaxed)
}

pub(crate) fn with_mut<R>(&mut self, f: impl FnOnce(&mut usize) -> R) -> R {
Expand Down

0 comments on commit 1968565

Please sign in to comment.