Skip to content

Commit c44af3e

Browse files
committed
feat(process): 完成了delete task
- 完善了TaskManager的delete_task函数
1 parent 96b29f5 commit c44af3e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

kernel/src/process/task.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ pub struct Task {
3535

3636
/// The priority of the kernel (1-8)
3737
priority: u8,
38+
39+
/// The entry point of the task.
40+
entry_point: usize,
3841
}
3942

4043
impl Task {
4144
/// Create a new task object.
42-
pub fn new(id: u16, priority: u8) -> Self {
45+
pub fn new(id: u16, priority: u8, entry_point: usize) -> Self {
4346
Self {
4447
id,
4548
state: TaskState::Ready,
4649
priority,
50+
entry_point,
4751
}
4852
}
4953

@@ -74,7 +78,7 @@ impl TaskManager {
7478
}
7579
}
7680

77-
pub fn create_task(&mut self, priority: u8) {
81+
pub fn create_task(&mut self, priority: u8, entry_point: usize) {
7882
// Allocate a task id
7983
let mut task_id = self.next_tid;
8084

@@ -84,7 +88,7 @@ impl TaskManager {
8488
}
8589

8690
// Push the task to the tasks container
87-
self.tasks.push(Task::new(task_id, priority));
91+
self.tasks.push(Task::new(task_id, priority, entry_point));
8892

8993
// Set the current id is allocated.
9094
self.allocated_tid.push(task_id);
@@ -99,6 +103,12 @@ impl TaskManager {
99103
return Err("The task ID is unable to discovor.");
100104
}
101105

106+
// Remove the task from [`tasks`].
107+
self.tasks.retain(|task| task.id != task_id);
108+
109+
// Remove the task from [`allocated_tid`].
110+
self.allocated_tid.retain(|id| *id != task_id);
111+
102112
// Find the task to remove from [`tasks`].
103113
Ok(())
104114
}

0 commit comments

Comments
 (0)