mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-23 09:56:24 +04:00
add_task->wakeup_task
This commit is contained in:
parent
1f5b1cc4d6
commit
d6362da0ac
@ -1,5 +1,5 @@
|
||||
use crate::sync::{Mutex, UPSafeCell};
|
||||
use crate::task::{add_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use crate::task::{wakeup_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
pub struct Condvar {
|
||||
@ -24,7 +24,7 @@ impl Condvar {
|
||||
pub fn signal(&self) {
|
||||
let mut inner = self.inner.exclusive_access();
|
||||
if let Some(task) = inner.wait_queue.pop_front() {
|
||||
add_task(task);
|
||||
wakeup_task(task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::UPSafeCell;
|
||||
use crate::task::TaskControlBlock;
|
||||
use crate::task::{add_task, current_task};
|
||||
use crate::task::{wakeup_task, current_task};
|
||||
use crate::task::{block_current_and_run_next, suspend_current_and_run_next};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
@ -80,7 +80,7 @@ impl Mutex for MutexBlocking {
|
||||
let mut mutex_inner = self.inner.exclusive_access();
|
||||
assert!(mutex_inner.locked);
|
||||
if let Some(waking_task) = mutex_inner.wait_queue.pop_front() {
|
||||
add_task(waking_task);
|
||||
wakeup_task(waking_task);
|
||||
} else {
|
||||
mutex_inner.locked = false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::task::{add_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use crate::task::{wakeup_task, block_current_and_run_next, current_task, TaskControlBlock};
|
||||
use alloc::{collections::VecDeque, sync::Arc};
|
||||
|
||||
pub struct Semaphore {
|
||||
@ -28,7 +28,7 @@ impl Semaphore {
|
||||
inner.count += 1;
|
||||
if inner.count <= 0 {
|
||||
if let Some(task) = inner.wait_queue.pop_front() {
|
||||
add_task(task);
|
||||
wakeup_task(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{ProcessControlBlock, TaskControlBlock};
|
||||
use super::{ProcessControlBlock, TaskControlBlock, TaskStatus};
|
||||
use crate::sync::UPSafeCell;
|
||||
use alloc::collections::{BTreeMap, VecDeque};
|
||||
use alloc::sync::Arc;
|
||||
@ -42,6 +42,13 @@ pub fn add_task(task: Arc<TaskControlBlock>) {
|
||||
TASK_MANAGER.exclusive_access().add(task);
|
||||
}
|
||||
|
||||
pub fn wakeup_task(task: Arc<TaskControlBlock>) {
|
||||
let mut task_inner = task.inner_exclusive_access();
|
||||
task_inner.task_status = TaskStatus::Ready;
|
||||
drop(task_inner);
|
||||
add_task(task);
|
||||
}
|
||||
|
||||
pub fn remove_task(task: Arc<TaskControlBlock>) {
|
||||
TASK_MANAGER.exclusive_access().remove(task);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use crate::timer::remove_timer;
|
||||
|
||||
pub use context::TaskContext;
|
||||
pub use id::{kstack_alloc, pid_alloc, KernelStack, PidHandle, IDLE_PID};
|
||||
pub use manager::{add_task, remove_task, pid2process, remove_from_pid2process};
|
||||
pub use manager::{add_task, wakeup_task, remove_task, pid2process, remove_from_pid2process};
|
||||
pub use processor::{
|
||||
current_kstack_top, current_process, current_task, current_trap_cx, current_trap_cx_user_va,
|
||||
current_user_token, run_tasks, schedule, take_current_task,
|
||||
|
@ -3,7 +3,7 @@ use core::cmp::Ordering;
|
||||
use crate::config::CLOCK_FREQ;
|
||||
use crate::sbi::set_timer;
|
||||
use crate::sync::UPSafeCell;
|
||||
use crate::task::{add_task, TaskControlBlock};
|
||||
use crate::task::{wakeup_task, TaskControlBlock};
|
||||
use alloc::collections::BinaryHeap;
|
||||
use alloc::sync::Arc;
|
||||
use lazy_static::*;
|
||||
@ -76,7 +76,7 @@ pub fn check_timer() {
|
||||
let mut timers = TIMERS.exclusive_access();
|
||||
while let Some(timer) = timers.peek() {
|
||||
if timer.expire_ms <= current_ms {
|
||||
add_task(Arc::clone(&timer.task));
|
||||
wakeup_task(Arc::clone(&timer.task));
|
||||
timers.pop();
|
||||
} else {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user