mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
把调度器实例的裸指针改为Option (#262)
This commit is contained in:
@ -15,8 +15,7 @@ use crate::{
|
||||
use super::core::{sched_enqueue, Scheduler};
|
||||
|
||||
/// 声明全局的cfs调度器实例
|
||||
|
||||
pub static mut CFS_SCHEDULER_PTR: *mut SchedulerCFS = null_mut();
|
||||
pub static mut CFS_SCHEDULER_PTR: Option<Box<SchedulerCFS>> = None;
|
||||
|
||||
/// @brief 获取cfs调度器实例的可变引用
|
||||
#[inline]
|
||||
@ -26,18 +25,18 @@ pub fn __get_cfs_scheduler() -> &'static mut SchedulerCFS {
|
||||
|
||||
/// @brief 初始化cfs调度器
|
||||
pub unsafe fn sched_cfs_init() {
|
||||
if CFS_SCHEDULER_PTR.is_null() {
|
||||
CFS_SCHEDULER_PTR = Box::leak(Box::new(SchedulerCFS::new()));
|
||||
if CFS_SCHEDULER_PTR.is_none() {
|
||||
CFS_SCHEDULER_PTR = Some(Box::new(SchedulerCFS::new()));
|
||||
} else {
|
||||
kBUG!("Try to init CFS Scheduler twice.");
|
||||
panic!("Try to init CFS Scheduler twice.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief CFS队列(per-cpu的)
|
||||
#[derive(Debug)]
|
||||
struct CFSQueue {
|
||||
/// 当前cpu上执行的进程,剩余的时间片
|
||||
/// 当前cpu上执行的进程剩余的时间片
|
||||
cpu_exec_proc_jiffies: i64,
|
||||
/// 队列的锁
|
||||
lock: RawSpinlock,
|
||||
@ -100,7 +99,7 @@ impl CFSQueue {
|
||||
}
|
||||
}
|
||||
/// 获取运行队列的长度
|
||||
pub fn get_cfs_queue_size(&mut self) -> usize {
|
||||
fn get_cfs_queue_size(&mut self) -> usize {
|
||||
return self.queue.len();
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ use crate::{
|
||||
use super::core::{sched_enqueue, Scheduler};
|
||||
|
||||
/// 声明全局的rt调度器实例
|
||||
|
||||
pub static mut RT_SCHEDULER_PTR: *mut SchedulerRT = null_mut();
|
||||
pub static mut RT_SCHEDULER_PTR: Option<Box<SchedulerRT>> = None;
|
||||
|
||||
/// @brief 获取rt调度器实例的可变引用
|
||||
#[inline]
|
||||
@ -26,14 +25,13 @@ pub fn __get_rt_scheduler() -> &'static mut SchedulerRT {
|
||||
/// @brief 初始化rt调度器
|
||||
pub unsafe fn sched_rt_init() {
|
||||
kdebug!("rt scheduler init");
|
||||
if RT_SCHEDULER_PTR.is_null() {
|
||||
RT_SCHEDULER_PTR = Box::leak(Box::new(SchedulerRT::new()));
|
||||
if RT_SCHEDULER_PTR.is_none() {
|
||||
RT_SCHEDULER_PTR = Some(Box::new(SchedulerRT::new()));
|
||||
} else {
|
||||
kBUG!("Try to init RT Scheduler twice.");
|
||||
panic!("Try to init RT Scheduler twice.");
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief RT队列(per-cpu的)
|
||||
#[derive(Debug)]
|
||||
struct RTQueue {
|
||||
|
Reference in New Issue
Block a user