#![cfg(CONFIG_MMU)]
use crate::{
bindings,
mm::MmWithUser,
sync::aref::{ARef, AlwaysRefCounted},
};
use core::{ops::Deref, ptr::NonNull};
#[repr(transparent)]
pub struct MmWithUserAsync {
mm: MmWithUser,
}
unsafe impl Send for MmWithUserAsync {}
unsafe impl Sync for MmWithUserAsync {}
unsafe impl AlwaysRefCounted for MmWithUserAsync {
#[inline]
fn inc_ref(&self) {
unsafe { bindings::mmget(self.as_raw()) };
}
#[inline]
unsafe fn dec_ref(obj: NonNull<Self>) {
unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
}
}
impl Deref for MmWithUserAsync {
type Target = MmWithUser;
#[inline]
fn deref(&self) -> &MmWithUser {
&self.mm
}
}
impl MmWithUser {
#[inline]
pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
}
}