#[cfg(loom)]
pub(crate) use loom::sync::atomic::{AtomicBool, AtomicU32, fence};
#[cfg(all(not(loom), target_has_atomic = "32"))]
pub(crate) use core::sync::atomic::{AtomicBool, AtomicU32, fence};
#[cfg(all(not(loom), not(target_has_atomic = "32"), feature = "portable-atomic"))]
pub(crate) use portable_atomic::{AtomicBool, AtomicU32, fence};
pub(crate) use core::sync::atomic::Ordering;
#[cfg(loom)]
#[derive(Debug)]
pub(crate) struct TrackedCell<T>(loom::cell::UnsafeCell<T>);
#[cfg(not(loom))]
#[derive(Debug)]
pub(crate) struct TrackedCell<T>(core::cell::UnsafeCell<T>);
impl<T> TrackedCell<T> {
#[cfg(not(loom))]
#[inline(always)]
pub(crate) const fn new(value: T) -> Self {
Self(core::cell::UnsafeCell::new(value))
}
#[cfg(loom)]
#[inline(always)]
pub(crate) fn new(value: T) -> Self {
Self(loom::cell::UnsafeCell::new(value))
}
#[inline(always)]
pub(crate) fn with<R>(&self, f: impl FnOnce(*const T) -> R) -> R {
#[cfg(loom)]
{
self.0.with(f)
}
#[cfg(not(loom))]
{
f(self.0.get())
}
}
#[inline(always)]
pub(crate) fn with_mut<R>(&self, f: impl FnOnce(*mut T) -> R) -> R {
#[cfg(loom)]
{
self.0.with_mut(f)
}
#[cfg(not(loom))]
{
f(self.0.get())
}
}
}