Struct mmtk::util::rust_util::InitializeOnce
source · pub struct InitializeOnce<T: 'static> {
v: UnsafeCell<MaybeUninit<T>>,
once: Once,
}
Expand description
InitializeOnce creates an uninitialized value that needs to be manually initialized later. InitializeOnce
guarantees the value is only initialized once. This type is used to allow more efficient reads.
Unlike the lazy_static!
which checks whether the static is initialized
in every read, InitializeOnce has no extra check for reads.
Fields§
§v: UnsafeCell<MaybeUninit<T>>
§once: Once
This is used to guarantee init_fn
is only called once.
Implementations§
source§impl<T> InitializeOnce<T>
impl<T> InitializeOnce<T>
pub const fn new() -> Self
sourcepub fn initialize_once(&self, init_fn: &'static dyn Fn() -> T)
pub fn initialize_once(&self, init_fn: &'static dyn Fn() -> T)
Initialize the value. This should be called before ever using the struct.
If this method is called by multiple threads, the first thread will
initialize the value, and the other threads will be blocked until the
initialization is done (Once
returns).
sourcepub unsafe fn get_mut(&self) -> &mut T
pub unsafe fn get_mut(&self) -> &mut T
Get a mutable reference to the value. This is currently only used for SFTMap during plan creation (single threaded), and before the plan creation is done, the binding cannot use MMTK at all.
§Safety
The caller needs to make sure there is no race when mutating the value.
Trait Implementations§
source§impl<T> Deref for InitializeOnce<T>
impl<T> Deref for InitializeOnce<T>
impl<T> Sync for InitializeOnce<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for InitializeOnce<T>
impl<T> Send for InitializeOnce<T>where
T: Send,
impl<T> Unpin for InitializeOnce<T>where
T: Unpin,
impl<T> UnwindSafe for InitializeOnce<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more