use std::cell::UnsafeCell;
use std::fmt;
use std::ops::Deref;
pub(crate) struct AtomicU16 {
inner: UnsafeCell<std::sync::atomic::AtomicU16>,
}
unsafe impl Send for AtomicU16 {}
unsafe impl Sync for AtomicU16 {}
impl AtomicU16 {
pub(crate) const fn new(val: u16) -> AtomicU16 {
let inner = UnsafeCell::new(std::sync::atomic::AtomicU16::new(val));
AtomicU16 { inner }
}
pub(crate) unsafe fn unsync_load(&self) -> u16 {
self.load(std::sync::atomic::Ordering::Relaxed)
}
}
impl Deref for AtomicU16 {
type Target = std::sync::atomic::AtomicU16;
fn deref(&self) -> &Self::Target {
unsafe { &*self.inner.get() }
}
}
impl fmt::Debug for AtomicU16 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.deref().fmt(fmt)
}
}