mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 02:46:23 +04:00
Remove spin::Mutex in frame_allocator and memory_set.
This commit is contained in:
parent
6187cdafd6
commit
928a6f0d8c
@ -10,7 +10,6 @@ edition = "2018"
|
||||
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
||||
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
|
||||
buddy_system_allocator = "0.6"
|
||||
spin = "0.7.0"
|
||||
bitflags = "1.2.1"
|
||||
xmas-elf = "0.7.0"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{PhysAddr, PhysPageNum};
|
||||
use alloc::vec::Vec;
|
||||
use spin::Mutex;
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::config::MEMORY_END;
|
||||
use lazy_static::*;
|
||||
use core::fmt::{self, Debug, Formatter};
|
||||
@ -87,8 +87,9 @@ impl FrameAllocator for StackFrameAllocator {
|
||||
type FrameAllocatorImpl = StackFrameAllocator;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref FRAME_ALLOCATOR: Mutex<FrameAllocatorImpl> =
|
||||
Mutex::new(FrameAllocatorImpl::new());
|
||||
pub static ref FRAME_ALLOCATOR: UPSafeCell<FrameAllocatorImpl> = unsafe {
|
||||
UPSafeCell::new(FrameAllocatorImpl::new())
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_frame_allocator() {
|
||||
@ -96,20 +97,20 @@ pub fn init_frame_allocator() {
|
||||
fn ekernel();
|
||||
}
|
||||
FRAME_ALLOCATOR
|
||||
.lock()
|
||||
.exclusive_access()
|
||||
.init(PhysAddr::from(ekernel as usize).ceil(), PhysAddr::from(MEMORY_END).floor());
|
||||
}
|
||||
|
||||
pub fn frame_alloc() -> Option<FrameTracker> {
|
||||
FRAME_ALLOCATOR
|
||||
.lock()
|
||||
.exclusive_access()
|
||||
.alloc()
|
||||
.map(|ppn| FrameTracker::new(ppn))
|
||||
}
|
||||
|
||||
fn frame_dealloc(ppn: PhysPageNum) {
|
||||
FRAME_ALLOCATOR
|
||||
.lock()
|
||||
.exclusive_access()
|
||||
.dealloc(ppn);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ use alloc::vec::Vec;
|
||||
use riscv::register::satp;
|
||||
use alloc::sync::Arc;
|
||||
use lazy_static::*;
|
||||
use spin::Mutex;
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::config::{
|
||||
MEMORY_END,
|
||||
PAGE_SIZE,
|
||||
@ -30,9 +30,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref KERNEL_SPACE: Arc<Mutex<MemorySet>> = Arc::new(Mutex::new(
|
||||
MemorySet::new_kernel()
|
||||
));
|
||||
pub static ref KERNEL_SPACE: Arc<UPSafeCell<MemorySet>> = Arc::new(unsafe {
|
||||
UPSafeCell::new(MemorySet::new_kernel()
|
||||
)});
|
||||
}
|
||||
|
||||
pub struct MemorySet {
|
||||
@ -290,7 +290,7 @@ bitflags! {
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn remap_test() {
|
||||
let mut kernel_space = KERNEL_SPACE.lock();
|
||||
let mut kernel_space = KERNEL_SPACE.exclusive_access();
|
||||
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
|
||||
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
|
||||
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
|
||||
|
@ -15,5 +15,5 @@ pub use memory_set::remap_test;
|
||||
pub fn init() {
|
||||
heap_allocator::init_heap();
|
||||
frame_allocator::init_frame_allocator();
|
||||
KERNEL_SPACE.lock().activate();
|
||||
KERNEL_SPACE.exclusive_access().activate();
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ impl TaskControlBlock {
|
||||
// map a kernel-stack in kernel space
|
||||
let (kernel_stack_bottom, kernel_stack_top) = kernel_stack_position(app_id);
|
||||
KERNEL_SPACE
|
||||
.lock()
|
||||
.exclusive_access()
|
||||
.insert_framed_area(
|
||||
kernel_stack_bottom.into(),
|
||||
kernel_stack_top.into(),
|
||||
@ -47,7 +47,7 @@ impl TaskControlBlock {
|
||||
*trap_cx = TrapContext::app_init_context(
|
||||
entry_point,
|
||||
user_sp,
|
||||
KERNEL_SPACE.lock().token(),
|
||||
KERNEL_SPACE.exclusive_access().token(),
|
||||
kernel_stack_top,
|
||||
trap_handler as usize,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user