diff --git a/kernel/src/libs/lazy_init.rs b/kernel/src/libs/lazy_init.rs index 6db023b4..9afdbe7d 100644 --- a/kernel/src/libs/lazy_init.rs +++ b/kernel/src/libs/lazy_init.rs @@ -25,12 +25,7 @@ use core::sync::atomic::{AtomicBool, Ordering}; use super::spinlock::SpinLock; /// A wrapper around a value that is initialized lazily. -/// The value is initialized the first time it is accessed. -/// This is useful for initializing values that are expensive to initialize. -/// The value is initialized using the provided closure. -/// The closure is only called once, and the result is cached. -/// The value is not initialized if it is never accessed. -pub struct Lazy { +pub struct Lazy { /// The lock that is used to ensure that only one thread calls the init function at the same time. init_lock: SpinLock<()>, /// The value that is initialized lazily. @@ -39,7 +34,7 @@ pub struct Lazy { initialized: AtomicBool, } -impl Lazy { +impl Lazy { /// Creates a new `Lazy` value that will be initialized with the /// result of the closure `init`. pub const fn new() -> Lazy { @@ -122,7 +117,7 @@ impl Lazy { } } -impl Deref for Lazy { +impl Deref for Lazy { type Target = T; #[inline(always)] @@ -131,14 +126,14 @@ impl Deref for Lazy { } } -impl DerefMut for Lazy { +impl DerefMut for Lazy { #[inline(always)] fn deref_mut(&mut self) -> &mut T { return self.get_mut(); } } -impl Debug for Lazy { +impl Debug for Lazy { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(value) = self.try_get() { return write!(f, "Lazy({:?})", value); @@ -148,7 +143,7 @@ impl Debug for Lazy { } } -impl Drop for Lazy { +impl Drop for Lazy { fn drop(&mut self) { if self.initialized() { unsafe { @@ -157,3 +152,6 @@ impl Drop for Lazy { } } } + +unsafe impl Sync for Lazy {} +unsafe impl Send for Lazy {}