diff --git a/ch8/os/task/fn.add_initproc.html b/ch8/os/task/fn.add_initproc.html index bd7498f5..7b65835b 100644 --- a/ch8/os/task/fn.add_initproc.html +++ b/ch8/os/task/fn.add_initproc.html @@ -4,5 +4,5 @@
-

Function os::task::add_initproc

source · []
pub fn add_initproc()
+

Function os::task::add_initproc

source · []
pub fn add_initproc()
\ No newline at end of file diff --git a/ch8/os/task/fn.block_current_and_run_next.html b/ch8/os/task/fn.block_current_and_run_next.html index ef47bdfd..7f72d2c3 100644 --- a/ch8/os/task/fn.block_current_and_run_next.html +++ b/ch8/os/task/fn.block_current_and_run_next.html @@ -4,5 +4,5 @@
pub fn block_current_and_run_next()
+

Function os::task::block_current_and_run_next

source · []
pub fn block_current_and_run_next()
\ No newline at end of file diff --git a/ch8/os/task/fn.check_signals_of_current.html b/ch8/os/task/fn.check_signals_of_current.html index ee2c3b91..5ff855a0 100644 --- a/ch8/os/task/fn.check_signals_of_current.html +++ b/ch8/os/task/fn.check_signals_of_current.html @@ -4,5 +4,5 @@
pub fn check_signals_of_current() -> Option<(i32, &'static str)>
+

Function os::task::check_signals_of_current

source · []
pub fn check_signals_of_current() -> Option<(i32, &'static str)>
\ No newline at end of file diff --git a/ch8/os/task/fn.current_add_signal.html b/ch8/os/task/fn.current_add_signal.html index ae57127e..9a77e105 100644 --- a/ch8/os/task/fn.current_add_signal.html +++ b/ch8/os/task/fn.current_add_signal.html @@ -4,5 +4,5 @@
pub fn current_add_signal(signal: SignalFlags)
+

Function os::task::current_add_signal

source · []
pub fn current_add_signal(signal: SignalFlags)
\ No newline at end of file diff --git a/ch8/os/task/fn.exit_current_and_run_next.html b/ch8/os/task/fn.exit_current_and_run_next.html index a0368b0f..b8977f90 100644 --- a/ch8/os/task/fn.exit_current_and_run_next.html +++ b/ch8/os/task/fn.exit_current_and_run_next.html @@ -4,5 +4,5 @@
pub fn exit_current_and_run_next(exit_code: i32)
+

Function os::task::exit_current_and_run_next

source · []
pub fn exit_current_and_run_next(exit_code: i32)
\ No newline at end of file diff --git a/ch8/os/task/fn.suspend_current_and_run_next.html b/ch8/os/task/fn.suspend_current_and_run_next.html index fcfd9bd3..c30a3886 100644 --- a/ch8/os/task/fn.suspend_current_and_run_next.html +++ b/ch8/os/task/fn.suspend_current_and_run_next.html @@ -4,5 +4,5 @@
pub fn suspend_current_and_run_next()
+

Function os::task::suspend_current_and_run_next

source · []
pub fn suspend_current_and_run_next()
\ No newline at end of file diff --git a/ch8/os/task/index.html b/ch8/os/task/index.html index bb7d5294..b34891ad 100644 --- a/ch8/os/task/index.html +++ b/ch8/os/task/index.html @@ -4,7 +4,7 @@
-

Module os::task

source · []

Re-exports

+

Module os::task

source · []

Re-exports

pub use context::TaskContext;
pub use id::kstack_alloc;
pub use id::pid_alloc;
pub use id::KernelStack;
pub use id::PidHandle;
pub use manager::add_task;
pub use manager::pid2process;
pub use manager::remove_from_pid2process;
pub use processor::current_kstack_top;
pub use processor::current_process;
pub use processor::current_task;
pub use processor::current_trap_cx;
pub use processor::current_trap_cx_user_va;
pub use processor::current_user_token;
pub use processor::run_tasks;
pub use processor::schedule;
pub use processor::take_current_task;
pub use signal::SignalFlags;
pub use task::TaskControlBlock;
pub use task::TaskStatus;

Modules

context 🔒
id 🔒
manager 🔒
process 🔒
processor 🔒
signal 🔒
switch 🔒
task 🔒

Structs

Functions

diff --git a/ch8/os/task/struct.INITPROC.html b/ch8/os/task/struct.INITPROC.html index 386bfae5..82c6ac0a 100644 --- a/ch8/os/task/struct.INITPROC.html +++ b/ch8/os/task/struct.INITPROC.html @@ -4,11 +4,11 @@
-

Struct os::task::INITPROC

source · []
pub struct INITPROC {
+    

Struct os::task::INITPROC

source · []
pub struct INITPROC {
     __private_field: (),
-}

Fields

__private_field: ()

Trait Implementations

The resulting type after dereferencing.

-

Dereferences the value.

-

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

+}

Fields

__private_field: ()

Trait Implementations

The resulting type after dereferencing.

+

Dereferences the value.

+

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

diff --git a/ch8/src/os/task/mod.rs.html b/ch8/src/os/task/mod.rs.html index c817734f..b82298b2 100644 --- a/ch8/src/os/task/mod.rs.html +++ b/ch8/src/os/task/mod.rs.html @@ -132,6 +132,16 @@ 127 128 129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139
mod context;
 mod id;
 mod manager;
@@ -142,8 +152,9 @@
 #[allow(clippy::module_inception)]
 mod task;
 
+use self::id::TaskUserRes;
 use crate::fs::{open_file, OpenFlags};
-use alloc::sync::Arc;
+use alloc::{sync::Arc, vec::Vec};
 use lazy_static::*;
 use manager::fetch_task;
 use process::ProcessControlBlock;
@@ -220,12 +231,21 @@
         // deallocate user res (including tid/trap_cx/ustack) of all threads
         // it has to be done before we dealloc the whole memory_set
         // otherwise they will be deallocated twice
+        let mut recycle_res = Vec::<TaskUserRes>::new();
         for task in process_inner.tasks.iter().filter(|t| t.is_some()) {
             let task = task.as_ref().unwrap();
             let mut task_inner = task.inner_exclusive_access();
-            task_inner.res = None;
+            if let Some(res) = task_inner.res.take() {
+                recycle_res.push(res);
+            }
         }
+        // dealloc_tid and dealloc_user_res require access to PCB inner, so we
+        // need to collect those user res first, then release process_inner
+        // for now to avoid deadlock/double borrow problem.
+        drop(process_inner);
+        recycle_res.clear();
 
+        let mut process_inner = process.inner_exclusive_access();
         process_inner.children.clear();
         // deallocate other data in user space i.e. program code/data section
         process_inner.memory_set.recycle_data_pages();