Skip to content

Commit

Permalink
Split kernel-lib/alloc.rs to kernel-lib/allocator/
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Nov 16, 2023
1 parent 94757dc commit a74c59b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions kernel-lib/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod fixed_length_allocator;
pub use fixed_length_allocator::FixedLengthAllocator;
File renamed without changes.
1 change: 1 addition & 0 deletions kernel-lib/src/allocator/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struct A(FixedLengthAllocator);
2 changes: 1 addition & 1 deletion kernel-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(allocator_api)]
#![feature(generic_arg_infer)]

pub mod alloc;
pub mod allocator;
pub mod futures;
pub mod layer;
pub mod logger;
Expand Down
14 changes: 9 additions & 5 deletions kernel/src/alloc/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate alloc;
use alloc::boxed::Box;
use core::{alloc::LayoutError, mem::MaybeUninit};
use kernel_lib::alloc::FixedLengthAllocator;
use kernel_lib::allocator::FixedLengthAllocator;

const HEAP_SIZE: usize = 1 << 21;

Expand All @@ -14,15 +14,17 @@ pub fn alloc_with_boundary<T>(
alignment: usize,
boundary: usize,
) -> Result<Box<MaybeUninit<T>, &'static GlobalAllocator>, LayoutError> {
kernel_lib::alloc::alloc_with_boundary(&ALLOCATOR, alignment, boundary)
kernel_lib::allocator::fixed_length_allocator::alloc_with_boundary(
&ALLOCATOR, alignment, boundary,
)
}

pub fn alloc_with_boundary_with_default_else<T>(
alignment: usize,
boundary: usize,
default: impl FnOnce() -> T,
) -> Result<Box<T, &'static GlobalAllocator>, LayoutError> {
kernel_lib::alloc::alloc_with_boundary_with_default_else(
kernel_lib::allocator::fixed_length_allocator::alloc_with_boundary_with_default_else(
&ALLOCATOR, alignment, boundary, default,
)
}
Expand All @@ -32,7 +34,9 @@ pub fn alloc_array_with_boundary<T>(
alignment: usize,
boundary: usize,
) -> Result<Box<[MaybeUninit<T>], &'static GlobalAllocator>, LayoutError> {
kernel_lib::alloc::alloc_array_with_boundary(&ALLOCATOR, len, alignment, boundary)
kernel_lib::allocator::fixed_length_allocator::alloc_array_with_boundary(
&ALLOCATOR, len, alignment, boundary,
)
}

pub fn alloc_array_with_boundary_with_default_else<T>(
Expand All @@ -41,7 +45,7 @@ pub fn alloc_array_with_boundary_with_default_else<T>(
boundary: usize,
default: impl Fn() -> T,
) -> Result<Box<[T], &'static GlobalAllocator>, LayoutError> {
kernel_lib::alloc::alloc_array_with_boundary_with_default_else(
kernel_lib::allocator::fixed_length_allocator::alloc_array_with_boundary_with_default_else(
&ALLOCATOR, len, alignment, boundary, default,
)
}

0 comments on commit a74c59b

Please sign in to comment.