Skip to content

Commit

Permalink
sync: implement waiting queue
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Mar 9, 2023
1 parent c0ef78e commit e1b9619
Showing 1 changed file with 66 additions and 6 deletions.
72 changes: 66 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
}

#[inline]
pub const fn page_offset<U>(addr: usize, align: U) -> usize
pub const fn align_offset<U>(addr: usize, align: U) -> usize
where
U: ~const Into<usize>,
{
Expand All @@ -37,7 +37,27 @@ pub const fn is_aligned<U>(addr: usize, align: U) -> bool
where
U: ~const Into<usize>,
{
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)]
Expand Down Expand Up @@ -71,11 +91,11 @@ impl PhysAddr {
}

#[inline]
pub const fn page_offset<U>(&self, align: U) -> usize
pub const fn align_offset<U>(&self, align: U) -> usize
where
U: ~const Into<usize>,
{
page_offset(self.0, align)
align_offset(self.0, align)
}

#[inline]
Expand All @@ -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 {
Expand Down Expand Up @@ -120,11 +160,11 @@ impl VirtAddr {
}

#[inline]
pub const fn page_offset<U>(&self, align: U) -> usize
pub const fn align_offset<U>(&self, align: U) -> usize
where
U: ~const Into<usize>,
{
page_offset(self.0, align)
align_offset(self.0, align)
}

#[inline]
Expand All @@ -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<usize> for PhysAddr {
Expand Down

0 comments on commit e1b9619

Please sign in to comment.