mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 21:06:48 +00:00
Eliminate redundant Clone in hot path
This commit is contained in:
parent
3ef8f20de6
commit
c1e6f9a552
@ -35,12 +35,11 @@ impl core::fmt::Debug for IdleClassRq {
|
||||
|
||||
impl SchedClassRq for IdleClassRq {
|
||||
fn enqueue(&mut self, entity: Arc<Task>, _: Option<EnqueueFlags>) {
|
||||
let ptr = Arc::as_ptr(&entity);
|
||||
if let Some(t) = self.entity.replace(entity)
|
||||
&& ptr != Arc::as_ptr(&t)
|
||||
{
|
||||
panic!("Multiple `idle` entities spawned")
|
||||
}
|
||||
let old = self.entity.replace(entity);
|
||||
debug_assert!(
|
||||
old.is_none(),
|
||||
"the length of the idle queue should be no larger than 1"
|
||||
);
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
@ -52,7 +51,7 @@ impl SchedClassRq for IdleClassRq {
|
||||
}
|
||||
|
||||
fn pick_next(&mut self) -> Option<Arc<Task>> {
|
||||
self.entity.clone()
|
||||
self.entity.take()
|
||||
}
|
||||
|
||||
fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {
|
||||
|
@ -14,18 +14,18 @@ use super::{CurrentRuntime, SchedAttr, SchedClassRq};
|
||||
/// 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: Option<Arc<Task>>,
|
||||
entity: Option<Arc<Task>>,
|
||||
}
|
||||
|
||||
impl StopClassRq {
|
||||
pub fn new() -> Self {
|
||||
Self { thread: None }
|
||||
Self { entity: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for StopClassRq {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
if self.thread.is_some() {
|
||||
if self.entity.is_some() {
|
||||
write!(f, "Stop: occupied")?;
|
||||
} else {
|
||||
write!(f, "Stop: empty")?;
|
||||
@ -35,10 +35,12 @@ impl core::fmt::Debug for StopClassRq {
|
||||
}
|
||||
|
||||
impl SchedClassRq for StopClassRq {
|
||||
fn enqueue(&mut self, thread: Arc<Task>, _: Option<EnqueueFlags>) {
|
||||
if self.thread.replace(thread).is_some() {
|
||||
panic!("Multiple `stop` threads spawned")
|
||||
}
|
||||
fn enqueue(&mut self, entity: Arc<Task>, _: Option<EnqueueFlags>) {
|
||||
let old = self.entity.replace(entity);
|
||||
debug_assert!(
|
||||
old.is_none(),
|
||||
"the length of the stop queue should be no larger than 1"
|
||||
);
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
@ -46,15 +48,15 @@ impl SchedClassRq for StopClassRq {
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.thread.is_none()
|
||||
self.entity.is_none()
|
||||
}
|
||||
|
||||
fn pick_next(&mut self) -> Option<Arc<Task>> {
|
||||
self.thread.take()
|
||||
self.entity.take()
|
||||
}
|
||||
|
||||
fn update_current(&mut self, _: &CurrentRuntime, _: &SchedAttr, _flags: UpdateFlags) -> bool {
|
||||
// Stop threads has the lowest priority value. They should never be preempted.
|
||||
// Stop entities has the lowest priority value. They should never be preempted.
|
||||
false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user