#[cfg(loom)]
use loom::cell::UnsafeCell as InnerUnsafeCell;
#[cfg(loom)]
pub use loom::cell::MutPtr;
#[cfg(not(loom))]
use core::cell::UnsafeCell as InnerUnsafeCell;
#[derive(Debug)]
pub struct UnsafeCell<T>(InnerUnsafeCell<T>);
impl<T> UnsafeCell<T> {
#[cfg(not(loom))]
pub const fn new(data: T) -> UnsafeCell<T> {
UnsafeCell(InnerUnsafeCell::new(data))
}
#[cfg(loom)]
pub fn new(data: T) -> UnsafeCell<T> {
UnsafeCell(InnerUnsafeCell::new(data))
}
pub fn get_mut(&self) -> MutPtr<T> {
#[cfg(loom)]
return self.0.get_mut();
#[cfg(not(loom))]
return MutPtr(self.0.get());
}
pub fn as_mut(&mut self) -> &mut T {
#[cfg(not(loom))]
return self.0.get_mut();
#[cfg(loom)]
{
let ptr = self.get_mut();
let ptr = unsafe { ptr.deref() };
unsafe { core::mem::transmute(ptr) }
}
}
}
#[cfg(not(loom))]
pub struct MutPtr<T>(*mut T);
#[cfg(not(loom))]
impl<T> MutPtr<T> {
#[allow(clippy::mut_from_ref)]
pub unsafe fn deref(&self) -> &mut T {
&mut *self.0
}
}