#[cfg(loom)]
pub(crate) use loom::sync::atomic::{AtomicBool, Ordering};
#[cfg(loom)]
pub(crate) use loom::thread::yield_now;
#[cfg(not(loom))]
pub(crate) use core::sync::atomic::{AtomicBool, Ordering};
#[cfg(not(loom))]
pub(crate) use std::thread::yield_now;
#[cfg(not(loom))]
pub(crate) struct UnsafeCell<T>(core::cell::UnsafeCell<T>);
#[cfg(not(loom))]
impl<T> UnsafeCell<T> {
#[inline(always)]
pub(crate) const fn new(value: T) -> UnsafeCell<T> {
UnsafeCell(core::cell::UnsafeCell::new(value))
}
#[inline(always)]
pub(crate) fn with<R>(&self, f: impl FnOnce(*mut T) -> R) -> R {
f(self.0.get())
}
#[inline(always)]
pub(crate) fn get_mut(&mut self) -> &mut T {
self.0.get_mut()
}
#[inline(always)]
pub(crate) fn into_inner(self) -> T {
self.0.into_inner()
}
}
#[cfg(loom)]
pub(crate) struct UnsafeCell<T>(loom::cell::UnsafeCell<T>);
#[cfg(loom)]
impl<T> UnsafeCell<T> {
pub(crate) fn new(value: T) -> UnsafeCell<T> {
UnsafeCell(loom::cell::UnsafeCell::new(value))
}
pub(crate) fn with<R>(&self, f: impl FnOnce(*mut T) -> R) -> R {
self.0.with(|p| f(p.cast_mut()))
}
pub(crate) fn get_mut(&mut self) -> &mut T {
self.0.with_mut(|p| unsafe { &mut *p })
}
pub(crate) fn into_inner(self) -> T {
self.0.into_inner()
}
}