#[cfg(loom)]
use loom::cell::UnsafeCell;
#[cfg(not(loom))]
use std::cell::UnsafeCell;
#[derive(Debug)]
pub struct UCell<T>(UnsafeCell<T>);
impl<T> UCell<T> {
pub fn new(x: T) -> Self {
Self(UnsafeCell::new(x))
}
pub unsafe fn get(&self) -> T
where
T: Copy,
{
#[cfg(loom)]
{
*self.0.get().deref()
}
#[cfg(not(loom))]
{
*self.0.get()
}
}
pub unsafe fn set(&self, x: T) {
#[cfg(loom)]
{
*self.0.get_mut().deref() = x;
}
#[cfg(not(loom))]
{
*self.0.get() = x;
}
}
}
#[cfg(not(loom))]
#[cfg(feature = "coerce-unsized")]
impl<T, U> std::ops::CoerceUnsized<UCell<crate::ptr::Nullable<U>>>
for UCell<crate::ptr::Nullable<T>>
where
T: std::marker::Unsize<U> + ?Sized,
U: ?Sized,
{
}