//! Version of `MmWithUser` using `mmput_async`. //! //! This is a separate file from `mm.rs` due to the dependency on `CONFIG_MMU=y`. #![cfg(CONFIG_MMU)]
usecrate::{
bindings,
mm::MmWithUser,
types::{ARef, AlwaysRefCounted},
}; use core::{ops::Deref, ptr::NonNull};
/// A wrapper for the kernel's `struct mm_struct`. /// /// This type is identical to `MmWithUser` except that it uses `mmput_async` when dropping a /// refcount. This means that the destructor of `ARef<MmWithUserAsync>` is safe to call in atomic /// context. /// /// # Invariants /// /// Values of this type are always refcounted using `mmget`. The value of `mm_users` is non-zero. #[repr(transparent)] pubstruct MmWithUserAsync {
mm: MmWithUser,
}
// SAFETY: It is safe to call `mmput_async` on another thread than where `mmget` was called. unsafeimpl Send for MmWithUserAsync {} // SAFETY: All methods on `MmWithUserAsync` can be called in parallel from several threads. unsafeimpl Sync for MmWithUserAsync {}
// SAFETY: By the type invariants, this type is always refcounted. unsafeimpl AlwaysRefCounted for MmWithUserAsync { #[inline] fn inc_ref(&self) { // SAFETY: The pointer is valid since self is a reference. unsafe { bindings::mmget(self.as_raw()) };
}
#[inline] unsafefn dec_ref(obj: NonNull<Self>) { // SAFETY: The caller is giving up their refcount. unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
}
}
// Make all `MmWithUser` methods available on `MmWithUserAsync`. impl Deref for MmWithUserAsync { type Target = MmWithUser;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.