tokio/loom/std/
atomic_u32.rs
1use std::cell::UnsafeCell;
2use std::fmt;
3use std::ops::Deref;
4use std::panic;
5
6pub(crate) struct AtomicU32 {
8 inner: UnsafeCell<std::sync::atomic::AtomicU32>,
9}
10
11unsafe impl Send for AtomicU32 {}
12unsafe impl Sync for AtomicU32 {}
13impl panic::RefUnwindSafe for AtomicU32 {}
14impl panic::UnwindSafe for AtomicU32 {}
15
16impl AtomicU32 {
17 pub(crate) const fn new(val: u32) -> AtomicU32 {
18 let inner = UnsafeCell::new(std::sync::atomic::AtomicU32::new(val));
19 AtomicU32 { inner }
20 }
21
22 pub(crate) unsafe fn unsync_load(&self) -> u32 {
29 core::ptr::read(self.inner.get() as *const u32)
30 }
31}
32
33impl Deref for AtomicU32 {
34 type Target = std::sync::atomic::AtomicU32;
35
36 fn deref(&self) -> &Self::Target {
37 unsafe { &*self.inner.get() }
40 }
41}
42
43impl fmt::Debug for AtomicU32 {
44 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
45 self.deref().fmt(fmt)
46 }
47}