Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename nightly allocator API fns #55

Merged
merged 2 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions nucleus/src/mm/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use {
crate::println,
core::{
alloc::{AllocError, AllocRef, Layout},
alloc::{AllocError, Allocator, Layout},
cell::Cell,
ptr::NonNull,
},
Expand All @@ -20,9 +20,9 @@ pub struct BumpAllocator {
name: &'static str,
}

unsafe impl AllocRef for BumpAllocator {
unsafe impl Allocator for BumpAllocator {
/// Allocate a memory block from the pool.
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
let start = crate::mm::aligned_addr_unchecked(self.next.get(), layout.align());
let end = start + layout.size();

Expand Down Expand Up @@ -50,7 +50,7 @@ unsafe impl AllocRef for BumpAllocator {
}

/// A bump allocator doesn't care about releasing memory.
unsafe fn dealloc(&self, _ptr: NonNull<u8>, _layout: Layout) {}
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {}
}

impl BumpAllocator {
Expand All @@ -73,20 +73,20 @@ mod tests {
#[test_case]
fn test_allocates_within_init_range() {
let allocator = BumpAllocator::new(256, 512, "Test allocator 1");
let result1 = allocator.alloc(unsafe { Layout::from_size_align_unchecked(128, 1) });
let result1 = allocator.allocate(unsafe { Layout::from_size_align_unchecked(128, 1) });
assert!(result1.is_ok());
let result2 = allocator.alloc(unsafe { Layout::from_size_align_unchecked(128, 32) });
let result2 = allocator.allocate(unsafe { Layout::from_size_align_unchecked(128, 32) });
println!("{:?}", result2);
assert!(result2.is_ok());
let result3 = allocator.alloc(unsafe { Layout::from_size_align_unchecked(1, 1) });
let result3 = allocator.allocate(unsafe { Layout::from_size_align_unchecked(1, 1) });
assert!(result3.is_err());
}
// Creating with end <= start sshould fail
// @todo return Result<> from new?
#[test_case]
fn test_bad_allocator() {
let bad_allocator = BumpAllocator::new(512, 256, "Test allocator 2");
let result1 = bad_allocator.alloc(unsafe { Layout::from_size_align_unchecked(1, 1) });
let result1 = bad_allocator.allocate(unsafe { Layout::from_size_align_unchecked(1, 1) });
assert!(result1.is_err());
}
}
4 changes: 2 additions & 2 deletions nucleus/src/platform/rpi3/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ impl PreparedMailbox {
impl Mailbox {
/// Create a new mailbox in the DMA-able memory area.
pub fn new(base_addr: usize) -> ::core::result::Result<Mailbox, ()> {
use core::alloc::AllocRef;
use core::alloc::Allocator;
crate::DMA_ALLOCATOR
.lock(|dma| {
dma.alloc_zeroed(
dma.allocate_zeroed(
core::alloc::Layout::from_size_align(
MAILBOX_ITEMS_COUNT * core::mem::size_of::<u32>(),
MAILBOX_ALIGNMENT,
Expand Down
2 changes: 1 addition & 1 deletion nucleus/src/platform/rpi3/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ impl Power {
val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
self.PM_RSTC.set(val);

loop {}
crate::endless_sleep()
}
}