strat9_kernel/process/sched_classes/
nice.rs1use core::sync::atomic::{AtomicI32, Ordering};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
7pub struct NiceValue(i8);
8
9impl Default for NiceValue {
10 fn default() -> Self {
12 Self(0)
13 }
14}
15
16impl NiceValue {
17 pub const MIN: Self = Self(-20);
18 pub const MAX: Self = Self(19);
19
20 pub fn new(value: i8) -> Self {
23 Self(value.clamp(Self::MIN.0, Self::MAX.0))
24 }
25
26 pub const fn get(self) -> i8 {
28 self.0
29 }
30}
31
32#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
34pub struct Nice(NiceValue);
35
36impl Nice {
37 pub fn new(value: i8) -> Self {
39 Self(NiceValue::new(value))
40 }
41
42 pub const fn value(self) -> NiceValue {
44 self.0
45 }
46}
47
48pub struct AtomicNice(AtomicI32);
49
50impl AtomicNice {
51 pub const fn new(nice: Nice) -> Self {
53 Self(AtomicI32::new(nice.0 .0 as i32))
54 }
55
56 pub fn load(&self, order: Ordering) -> Nice {
58 Nice::new(self.0.load(order) as i8)
59 }
60
61 pub fn store(&self, nice: Nice, order: Ordering) {
63 self.0.store(nice.0 .0 as i32, order)
64 }
65}