tokio/loom/std/
atomic_u32.rs
1use std::cell::UnsafeCell;
2use std::fmt;
3use std::ops::Deref;
4
5pub(crate) struct AtomicU32 {
7 inner: UnsafeCell<std::sync::atomic::AtomicU32>,
8}
9
10unsafe impl Send for AtomicU32 {}
11unsafe impl Sync for AtomicU32 {}
12
13impl AtomicU32 {
14 pub(crate) const fn new(val: u32) -> AtomicU32 {
15 let inner = UnsafeCell::new(std::sync::atomic::AtomicU32::new(val));
16 AtomicU32 { inner }
17 }
18
19 pub(crate) unsafe fn unsync_load(&self) -> u32 {
26 self.load(std::sync::atomic::Ordering::Relaxed)
28 }
29}
30
31impl Deref for AtomicU32 {
32 type Target = std::sync::atomic::AtomicU32;
33
34 fn deref(&self) -> &Self::Target {
35 unsafe { &*self.inner.get() }
38 }
39}
40
41impl fmt::Debug for AtomicU32 {
42 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
43 self.deref().fmt(fmt)
44 }
45}