From e1b96199c3ddeb0d37789aac3504bd71d45b6499 Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Sun, 5 Mar 2023 23:38:53 +0800 Subject: [PATCH] sync: implement waiting queue --- src/lib.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 00c52f0..ad1dece 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ where } #[inline] -pub const fn page_offset(addr: usize, align: U) -> usize +pub const fn align_offset(addr: usize, align: U) -> usize where U: ~const Into, { @@ -37,7 +37,27 @@ pub const fn is_aligned(addr: usize, align: U) -> bool where U: ~const Into, { - page_offset(addr, align) == 0 + align_offset(addr, align) == 0 +} + +#[inline] +pub const fn align_down_4k(addr: usize) -> usize { + align_down(addr, PAGE_SIZE_4K) +} + +#[inline] +pub const fn align_up_4k(addr: usize) -> usize { + align_up(addr, PAGE_SIZE_4K) +} + +#[inline] +pub const fn align_offset_4k(addr: usize) -> usize { + align_offset(addr, PAGE_SIZE_4K) +} + +#[inline] +pub const fn is_aligned_4k(addr: usize) -> bool { + is_aligned(addr, PAGE_SIZE_4K) } #[repr(transparent)] @@ -71,11 +91,11 @@ impl PhysAddr { } #[inline] - pub const fn page_offset(&self, align: U) -> usize + pub const fn align_offset(&self, align: U) -> usize where U: ~const Into, { - page_offset(self.0, align) + align_offset(self.0, align) } #[inline] @@ -85,6 +105,26 @@ impl PhysAddr { { is_aligned(self.0, align) } + + #[inline] + pub const fn align_down_4k(&self) -> Self { + self.align_down(PAGE_SIZE_4K) + } + + #[inline] + pub const fn align_up_4k(&self) -> Self { + self.align_up(PAGE_SIZE_4K) + } + + #[inline] + pub const fn align_offset_4k(&self) -> usize { + self.align_offset(PAGE_SIZE_4K) + } + + #[inline] + pub const fn is_aligned_4k(&self) -> bool { + self.is_aligned(PAGE_SIZE_4K) + } } impl VirtAddr { @@ -120,11 +160,11 @@ impl VirtAddr { } #[inline] - pub const fn page_offset(&self, align: U) -> usize + pub const fn align_offset(&self, align: U) -> usize where U: ~const Into, { - page_offset(self.0, align) + align_offset(self.0, align) } #[inline] @@ -134,6 +174,26 @@ impl VirtAddr { { is_aligned(self.0, align) } + + #[inline] + pub const fn align_down_4k(&self) -> Self { + self.align_down(PAGE_SIZE_4K) + } + + #[inline] + pub const fn align_up_4k(&self) -> Self { + self.align_up(PAGE_SIZE_4K) + } + + #[inline] + pub const fn align_offset_4k(&self) -> usize { + self.align_offset(PAGE_SIZE_4K) + } + + #[inline] + pub const fn is_aligned_4k(&self) -> bool { + self.is_aligned(PAGE_SIZE_4K) + } } impl const From for PhysAddr {