spin::Mutex->UPSafeCell
This commit is contained in:
parent
c82861f205
commit
3c9b6d7d14
26 changed files with 239 additions and 188 deletions
|
@ -5,7 +5,7 @@ mod manager;
|
|||
mod processor;
|
||||
mod pid;
|
||||
|
||||
use crate::loader::{get_app_data_by_name};
|
||||
use crate::loader::get_app_data_by_name;
|
||||
use switch::__switch;
|
||||
use task::{TaskControlBlock, TaskStatus};
|
||||
use alloc::sync::Arc;
|
||||
|
@ -28,51 +28,51 @@ pub fn suspend_current_and_run_next() {
|
|||
// There must be an application running.
|
||||
let task = take_current_task().unwrap();
|
||||
|
||||
// ---- hold current PCB lock
|
||||
let mut task_inner = task.acquire_inner_lock();
|
||||
let task_cx_ptr2 = task_inner.get_task_cx_ptr2();
|
||||
// ---- access current TCB exclusively
|
||||
let mut task_inner = task.inner_exclusive_access();
|
||||
let task_cx_ptr = &mut task_inner.task_cx as *mut TaskContext;
|
||||
// Change status to Ready
|
||||
task_inner.task_status = TaskStatus::Ready;
|
||||
drop(task_inner);
|
||||
// ---- release current PCB lock
|
||||
// ---- release current PCB
|
||||
|
||||
// push back to ready queue.
|
||||
add_task(task);
|
||||
// jump to scheduling cycle
|
||||
schedule(task_cx_ptr2);
|
||||
schedule(task_cx_ptr);
|
||||
}
|
||||
|
||||
pub fn exit_current_and_run_next(exit_code: i32) {
|
||||
// take from Processor
|
||||
let task = take_current_task().unwrap();
|
||||
// **** hold current PCB lock
|
||||
let mut inner = task.acquire_inner_lock();
|
||||
// **** access current TCB exclusively
|
||||
let mut inner = task.inner_exclusive_access();
|
||||
// Change status to Zombie
|
||||
inner.task_status = TaskStatus::Zombie;
|
||||
// Record exit code
|
||||
inner.exit_code = exit_code;
|
||||
// do not move to its parent but under initproc
|
||||
|
||||
// ++++++ hold initproc PCB lock here
|
||||
// ++++++ access initproc TCB exclusively
|
||||
{
|
||||
let mut initproc_inner = INITPROC.acquire_inner_lock();
|
||||
let mut initproc_inner = INITPROC.inner_exclusive_access();
|
||||
for child in inner.children.iter() {
|
||||
child.acquire_inner_lock().parent = Some(Arc::downgrade(&INITPROC));
|
||||
child.inner_exclusive_access().parent = Some(Arc::downgrade(&INITPROC));
|
||||
initproc_inner.children.push(child.clone());
|
||||
}
|
||||
}
|
||||
// ++++++ release parent PCB lock here
|
||||
// ++++++ release parent PCB
|
||||
|
||||
inner.children.clear();
|
||||
// deallocate user space
|
||||
inner.memory_set.recycle_data_pages();
|
||||
drop(inner);
|
||||
// **** release current PCB lock
|
||||
// **** release current PCB
|
||||
// drop task manually to maintain rc correctly
|
||||
drop(task);
|
||||
// we do not have to save task context
|
||||
let _unused: usize = 0;
|
||||
schedule(&_unused as *const _);
|
||||
let mut _unused = TaskContext::zero_init();
|
||||
schedule(&mut _unused as *mut _);
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue