Small fix
This commit is contained in:
parent
3415b37660
commit
3e62dc406f
|
@ -25,7 +25,7 @@ impl<T: Clone + PartialEq> Scheduler<T> for FifoScheduler<T> {
|
|||
None
|
||||
}
|
||||
fn next_task(&mut self) -> Option<T> {
|
||||
// 从头部取出放回尾部
|
||||
// 从头部取出
|
||||
self.pool.pop_front()
|
||||
}
|
||||
fn peek_next_task(&self) -> Option<&T> {
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<T: Clone + PartialEq, const N: usize> Scheduler<T> for RingFifoScheduler<T,
|
|||
None
|
||||
}
|
||||
fn next_task(&mut self) -> Option<T> {
|
||||
// 从头部取出放回尾部
|
||||
// 从头部取出
|
||||
self.ring.pop_front()
|
||||
}
|
||||
fn peek_next_task(&self) -> Option<&T> {
|
||||
|
|
|
@ -76,10 +76,10 @@ pub extern "C" fn rust_main() -> ! {
|
|||
|
||||
// todo: 这里要有个地方往tp里写东西,目前会出错
|
||||
let process = process::Process::new_kernel().expect("create process 1");
|
||||
let stack_handle = process.alloc_stack().expect("alloc initial stack");
|
||||
// let stack_handle = process.alloc_stack().expect("alloc initial stack");
|
||||
|
||||
let task_1 = process::Task::new_kernel(task_1(), process.clone(), stack_handle.clone());
|
||||
let task_2 = process::Task::new_kernel(task_2(), process, stack_handle);
|
||||
let task_1 = process::Task::new_kernel(task_1(), process.clone());
|
||||
let task_2 = process::Task::new_kernel(task_2(), process);
|
||||
|
||||
let shared_scheduler = process::shared_scheduler();
|
||||
println!("Shared scheduler: {:?}", shared_scheduler);
|
||||
|
@ -95,9 +95,16 @@ pub extern "C" fn rust_main() -> ! {
|
|||
}
|
||||
|
||||
async fn task_1() {
|
||||
println!("hello world from 1!")
|
||||
// let new_task = process::Task::new_kernel(task_3(), process);
|
||||
// let shared_scheduler = process::shared_scheduler();
|
||||
// process::shared_add_task(shared_scheduler, handle);
|
||||
println!("hello world from 1!");
|
||||
}
|
||||
|
||||
async fn task_2() {
|
||||
println!("hello world from 2!")
|
||||
}
|
||||
|
||||
// async fn task_3() {
|
||||
// println!("hello world from 3!")
|
||||
// }
|
||||
|
|
|
@ -97,4 +97,7 @@ impl SharedAddressSpace {
|
|||
drop(Box::into_raw(bx));
|
||||
ans
|
||||
}
|
||||
// fn current_process() -> Process {
|
||||
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use core::ops::Range;
|
|||
use core::future::Future;
|
||||
use alloc::boxed::Box;
|
||||
use crate::{interrupt::TrapFrame, memory::VirtualAddress};
|
||||
use crate::process::{Process, SharedTaskHandle, SharedAddressSpace};
|
||||
use crate::process::{Process, SharedTaskHandle};
|
||||
use core::pin::Pin;
|
||||
|
||||
lazy_static! {
|
||||
|
@ -13,6 +13,8 @@ lazy_static! {
|
|||
}
|
||||
|
||||
/// 任务的信息
|
||||
// TODO: 只是内核任务,用户任务由用户自己定义表现方式
|
||||
// 如果要运行用户的进程,首先切换到用户的地址空间,其中包含一个初始化好的栈和剩余空间,然后在里面增加用户的任务
|
||||
pub struct Task {
|
||||
/// 任务的编号
|
||||
pub id: TaskId,
|
||||
|
@ -30,8 +32,10 @@ pub struct TaskId(usize);
|
|||
|
||||
/// 任务信息的可变部分
|
||||
pub struct TaskInner {
|
||||
/// 本任务运行的栈;任务被强制中断暂停时,下一个任务使用新分配的栈
|
||||
pub stack: Range<VirtualAddress>,
|
||||
/// 本任务运行的栈
|
||||
///
|
||||
/// 内核任务复用执行器的栈。用户任务占有一个栈,下一个任务复用此栈。强制中断暂停时,下一个任务使用新分配的栈。
|
||||
pub stack: Option<Range<VirtualAddress>>,
|
||||
/// 任务的执行上下文;仅当遇到中断强制暂停时,这里是Some
|
||||
pub context: Option<TrapFrame>,
|
||||
/// 任务是否正在休眠
|
||||
|
@ -41,20 +45,11 @@ pub struct TaskInner {
|
|||
}
|
||||
|
||||
impl Task {
|
||||
/// 创建一个任务,需要输入创建好的栈
|
||||
/// 创建一个任务,将会复用执行器的栈
|
||||
pub fn new_kernel(
|
||||
future: impl Future<Output = ()> + 'static + Send + Sync,
|
||||
process: Arc<Process>,
|
||||
stack: Range<VirtualAddress>
|
||||
) -> Arc<Task> {
|
||||
// 构建上下文
|
||||
let stack_top: usize = stack.end.into();
|
||||
let context = TrapFrame::new_task_context(
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
stack_top
|
||||
); // todo: 逻辑是不是错了?
|
||||
// 任务编号自增
|
||||
let task_id = {
|
||||
let counter = TASK_ID_COUNTER.lock();
|
||||
|
@ -66,8 +61,8 @@ impl Task {
|
|||
id: task_id,
|
||||
process,
|
||||
inner: Mutex::new(TaskInner {
|
||||
stack,
|
||||
context: Some(context),
|
||||
stack: None,
|
||||
context: None,
|
||||
sleeping: false,
|
||||
ended: false,
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue