Struct mycelium_util::sync::cell::UnsafeCell
source · pub struct UnsafeCell<T> { /* private fields */ }
loom
only.Expand description
A variant of core::cell::UnsafeCell
that may be checked when
Loom model checking is enabled.
This type is similar to core::cell::UnsafeCell
, except when the
cfg(loom)
cfg flag is enabled, it is replaced with a variant that
participates in Loom model checking. See loom::cell::UnsafeCell
for details on this.
When cfg(loom)
is not set, this type is essentially a
core::cell::UnsafeCell
, but with an API that matches that of the
checked Loom cell.
Instead of providing a get()
API, this version of UnsafeCell
provides
with
and with_mut
. Both functions take a closure in order to track the
start and end of the access to the underlying cell.
Implementations§
source§impl<T> UnsafeCell<T>
impl<T> UnsafeCell<T>
sourcepub const fn new(data: T) -> Self
pub const fn new(data: T) -> Self
Construct a new instance of UnsafeCell
which will wrap the specified
value.
sourcepub fn with<F, R>(&self, f: F) -> R
pub fn with<F, R>(&self, f: F) -> R
Get an immutable pointer to the wrapped value.
Panics
When running under loom
, this function will panic if the access is
not valid under the Rust memory model.
sourcepub fn with_mut<F, R>(&self, f: F) -> R
pub fn with_mut<F, R>(&self, f: F) -> R
Get a mutable pointer to the wrapped value.
Panics
When running under loom
, this function will panic if the access is
not valid under the Rust memory model.
sourcepub fn get(&self) -> ConstPtr<T>
pub fn get(&self) -> ConstPtr<T>
Get an immutable pointer to the wrapped value.
This function returns a ConstPtr
guard, which is analogous to a
*const T
, but tracked by Loom when the cfg(loom)
cfg flag is
enabled. As long as the returned ConstPtr
exists, Loom will
consider the cell to be accessed immutably.
This means that any mutable accesses (e.g. calls to with_mut
or
get_mut
) while the returned guard is live will result in a panic.
Panics
This function will panic if the access is not valid under the Rust memory
model, if cfg(loom)
is enabled.
sourcepub fn get_mut(&self) -> MutPtr<T>
pub fn get_mut(&self) -> MutPtr<T>
Get a mutable pointer to the wrapped value.
This function returns a MutPtr
guard, which is analogous to a
*mut T
, but tracked by Loom when the cfg(loom)
cfg flag is
enabled. As long as the returned MutPtr
exists, Loom will
consider the cell to be accessed mutably.
This means that any concurrent mutable or immutable accesses (e.g. calls
to with
, with_mut
, get
, or get_mut
) while the returned
guard is live will result in a panic.
Panics
This function will panic if the access is not valid under the Rust memory
model, if cfg(loom)
is enabled.