mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-22 23:26:33 +11:00
only use critical section once
This commit is contained in:
parent
17de9a42bd
commit
03e9517215
2 changed files with 31 additions and 30 deletions
|
@ -4,7 +4,7 @@ use core::cell::RefCell;
|
|||
use core::ptr::NonNull;
|
||||
|
||||
use crate::interrupt::free;
|
||||
use bare_metal::Mutex;
|
||||
use bare_metal::{CriticalSection, Mutex};
|
||||
|
||||
use super::bump_allocator::BumpAllocator;
|
||||
use super::SendNonNull;
|
||||
|
@ -47,9 +47,9 @@ impl BlockAllocator {
|
|||
}
|
||||
}
|
||||
|
||||
fn new_block(&self, layout: Layout) -> *mut u8 {
|
||||
fn new_block(&self, layout: Layout, cs: &CriticalSection) -> *mut u8 {
|
||||
let overall_layout = Block::either_layout(layout);
|
||||
self.inner_allocator.alloc_safe(overall_layout)
|
||||
self.inner_allocator.alloc_critical(overall_layout, cs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ unsafe impl GlobalAlloc for BlockAllocator {
|
|||
list_ptr = &mut curr_block.next;
|
||||
}
|
||||
|
||||
self.new_block(layout)
|
||||
self.new_block(layout, key)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use core::ptr::NonNull;
|
|||
|
||||
use super::SendNonNull;
|
||||
use crate::interrupt::free;
|
||||
use bare_metal::Mutex;
|
||||
use bare_metal::{CriticalSection, Mutex};
|
||||
|
||||
pub(crate) struct BumpAllocator {
|
||||
current_ptr: Mutex<RefCell<Option<SendNonNull<u8>>>>,
|
||||
|
@ -19,9 +19,8 @@ impl BumpAllocator {
|
|||
}
|
||||
|
||||
impl BumpAllocator {
|
||||
pub fn alloc_safe(&self, layout: Layout) -> *mut u8 {
|
||||
free(|key| {
|
||||
let mut current_ptr = self.current_ptr.borrow(*key).borrow_mut();
|
||||
pub fn alloc_critical(&self, layout: Layout, cs: &CriticalSection) -> *mut u8 {
|
||||
let mut current_ptr = self.current_ptr.borrow(*cs).borrow_mut();
|
||||
|
||||
let ptr = if let Some(c) = *current_ptr {
|
||||
c.as_ptr() as usize
|
||||
|
@ -44,7 +43,9 @@ impl BumpAllocator {
|
|||
*current_ptr = NonNull::new(new_current_ptr as *mut _).map(SendNonNull);
|
||||
|
||||
resulting_ptr as *mut _
|
||||
})
|
||||
}
|
||||
pub fn alloc_safe(&self, layout: Layout) -> *mut u8 {
|
||||
free(|key| self.alloc_critical(layout, key))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue