diff --git a/kernel/src/sched/sched_class/mod.rs b/kernel/src/sched/sched_class/mod.rs index bb7f39d9b..51d940a50 100644 --- a/kernel/src/sched/sched_class/mod.rs +++ b/kernel/src/sched/sched_class/mod.rs @@ -49,7 +49,7 @@ pub struct ClassScheduler { /// scheduling classes in its corresponding CPU core. The current task of this CPU /// core is also stored in this structure. struct PerCpuClassRqSet { - stop: Arc, + stop: stop::StopClassRq, real_time: real_time::RealTimeClassRq, fair: fair::FairClassRq, idle: idle::IdleClassRq, @@ -249,10 +249,9 @@ impl Scheduler for ClassScheduler { impl ClassScheduler { pub fn new() -> Self { - let stop = stop::StopClassRq::new(); let class_rq = |cpu| { SpinLock::new(PerCpuClassRqSet { - stop: stop.clone(), + stop: stop::StopClassRq::new(), real_time: real_time::RealTimeClassRq::new(cpu), fair: fair::FairClassRq::new(cpu), idle: idle::IdleClassRq::new(), diff --git a/kernel/src/sched/sched_class/stop.rs b/kernel/src/sched/sched_class/stop.rs index c1b5a5978..708f5567d 100644 --- a/kernel/src/sched/sched_class/stop.rs +++ b/kernel/src/sched/sched_class/stop.rs @@ -7,20 +7,18 @@ use super::*; /// This is a singleton class, meaning that only one thread can be in this class at a time. /// This is used for the most critical tasks, such as powering off and rebooting. pub(super) struct StopClassRq { - thread: SpinLock>>, + thread: Option>, } impl StopClassRq { - pub fn new() -> Arc { - Arc::new(StopClassRq { - thread: SpinLock::new(None), - }) + pub fn new() -> Self { + Self { thread: None } } } impl core::fmt::Debug for StopClassRq { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - if self.thread.lock().is_some() { + if self.thread.is_some() { write!(f, "Stop: occupied")?; } else { write!(f, "Stop: empty")?; @@ -29,9 +27,9 @@ impl core::fmt::Debug for StopClassRq { } } -impl SchedClassRq for Arc { +impl SchedClassRq for StopClassRq { fn enqueue(&mut self, thread: Arc, _: Option) { - if self.thread.lock().replace(thread).is_some() { + if self.thread.replace(thread).is_some() { panic!("Multiple `stop` threads spawned") } } @@ -41,11 +39,11 @@ impl SchedClassRq for Arc { } fn is_empty(&mut self) -> bool { - self.thread.lock().is_none() + self.thread.is_none() } fn pick_next(&mut self) -> Option> { - self.thread.lock().take() + self.thread.take() } fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {