mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +00:00
Use Ord::clamp
to simplify the scheduling priority value
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ef075d15d0
commit
9711d43c84
@ -30,12 +30,8 @@ impl Nice {
|
|||||||
/// Values given beyond the permissible range are automatically adjusted
|
/// Values given beyond the permissible range are automatically adjusted
|
||||||
/// to the nearest boundary value.
|
/// to the nearest boundary value.
|
||||||
pub fn new(raw: i8) -> Self {
|
pub fn new(raw: i8) -> Self {
|
||||||
if raw > Self::MAX.to_raw() {
|
Self {
|
||||||
Self::MAX
|
value: raw.clamp(Self::MIN.to_raw(), Self::MAX.to_raw()),
|
||||||
} else if raw < Self::MIN.to_raw() {
|
|
||||||
Self::MIN
|
|
||||||
} else {
|
|
||||||
Self { value: raw }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +83,8 @@ impl Priority {
|
|||||||
/// Values given beyond the permissible range are automatically adjusted
|
/// Values given beyond the permissible range are automatically adjusted
|
||||||
/// to the nearest boundary value.
|
/// to the nearest boundary value.
|
||||||
pub fn new(raw: u8) -> Self {
|
pub fn new(raw: u8) -> Self {
|
||||||
if raw > Self::MAX.to_raw() {
|
Self {
|
||||||
Self::MAX
|
value: raw.clamp(Self::MIN.to_raw(), Self::MAX.to_raw()),
|
||||||
} else if raw < Self::MIN.to_raw() {
|
|
||||||
Self::MIN
|
|
||||||
} else {
|
|
||||||
Self { value: raw }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +12,7 @@ use crate::{
|
|||||||
pub fn sys_set_priority(which: i32, who: u32, prio: i32) -> Result<SyscallReturn> {
|
pub fn sys_set_priority(which: i32, who: u32, prio: i32) -> Result<SyscallReturn> {
|
||||||
let prio_target = PriorityTarget::new(which, who)?;
|
let prio_target = PriorityTarget::new(which, who)?;
|
||||||
let new_nice = {
|
let new_nice = {
|
||||||
let norm_prio = if prio > i8::MAX as i32 {
|
let norm_prio = prio.clamp(i8::MIN as i32, i8::MAX as i32) as i8;
|
||||||
i8::MAX
|
|
||||||
} else if prio < i8::MIN as i32 {
|
|
||||||
i8::MIN
|
|
||||||
} else {
|
|
||||||
prio as i8
|
|
||||||
};
|
|
||||||
Nice::new(norm_prio)
|
Nice::new(norm_prio)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user