| 1 | |
| 2 |
|
| 3 | |
| 4 |
|
| 5 | |
| 6 | |
| 7 | |
| 8 | #![cfg(CONFIG_MMU)]
|
| 9 |
|
| 10 | use crate::{
|
| 11 | bindings,
|
| 12 | mm::MmWithUser,
|
| 13 | sync::aref::{ARef, AlwaysRefCounted},
|
| 14 | };
|
| 15 | use core::{ops::Deref, ptr::NonNull};
|
| 16 |
|
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | #[repr(transparent)]
|
| 27 | pub struct MmWithUserAsync {
|
| 28 | mm: MmWithUser,
|
| 29 | }
|
| 30 |
|
| 31 | |
| 32 | unsafe impl Send for MmWithUserAsync {}
|
| 33 | |
| 34 | unsafe impl Sync for MmWithUserAsync {}
|
| 35 |
|
| 36 | |
| 37 | unsafe impl AlwaysRefCounted for MmWithUserAsync {
|
| 38 | #[inline]
|
| 39 | fn inc_ref(&self) {
|
| 40 | |
| 41 | unsafe { bindings::mmget(self.as_raw()) };
|
| 42 | }
|
| 43 |
|
| 44 | #[inline]
|
| 45 | unsafe fn dec_ref(obj: NonNull<Self>) {
|
| 46 | |
| 47 | unsafe { bindings::mmput_async(obj.cast().as_ptr()) };
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | |
| 52 | impl Deref for MmWithUserAsync {
|
| 53 | type Target = MmWithUser;
|
| 54 |
|
| 55 | #[inline]
|
| 56 | fn deref(&self) -> &MmWithUser {
|
| 57 | &self.mm
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | impl MmWithUser {
|
| 62 | |
| 63 | #[inline]
|
| 64 | pub fn into_mmput_async(me: ARef<MmWithUser>) -> ARef<MmWithUserAsync> {
|
| 65 | |
| 66 | unsafe { ARef::from_raw(ARef::into_raw(me).cast()) }
|
| 67 | }
|
| 68 | }
|