#[cfg(not(loom))]
pub(super) use core::hint::spin_loop;
#[cfg(not(loom))]
pub(super) use core::sync::atomic::{
AtomicPtr, AtomicU32, AtomicU64, AtomicUsize, Ordering, fence,
};
#[cfg(loom)]
pub(super) use loom::hint::spin_loop;
#[cfg(loom)]
pub(super) use loom::sync::atomic::fence;
#[cfg(loom)]
pub(super) use loom::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, AtomicUsize, Ordering};
#[repr(align(128))]
pub(super) struct CachePadded<T>(pub(super) T);
#[cfg_attr(not(loom), repr(transparent))]
pub(super) struct UnsafeCell<T> {
#[cfg(loom)]
inner: loom::cell::UnsafeCell<T>,
#[cfg(not(loom))]
inner: core::cell::UnsafeCell<T>,
}
impl<T> UnsafeCell<T> {
pub(super) fn new(value: T) -> Self {
Self {
#[cfg(loom)]
inner: loom::cell::UnsafeCell::new(value),
#[cfg(not(loom))]
inner: core::cell::UnsafeCell::new(value),
}
}
pub(super) fn with<R>(&self, f: impl FnOnce(*const T) -> R) -> R {
#[cfg(loom)]
{
self.inner.with(f)
}
#[cfg(not(loom))]
{
f(self.inner.get().cast_const())
}
}
pub(super) fn with_mut<R>(&self, f: impl FnOnce(*mut T) -> R) -> R {
#[cfg(loom)]
{
self.inner.with_mut(f)
}
#[cfg(not(loom))]
{
f(self.inner.get())
}
}
#[cfg(any(not(feature = "std"), loom))]
pub(super) fn into_inner(self) -> T {
self.inner.into_inner()
}
#[cfg(loom)]
pub(super) fn write(&self) -> loom::cell::MutPtr<T> {
self.inner.get_mut()
}
#[cfg(loom)]
pub(super) fn read(&self) -> loom::cell::ConstPtr<T> {
self.inner.get()
}
}