1
0
Fork 0
forked from AbleOS/ableos
ableos_time/ableos/src/kernel_state.rs

37 lines
789 B
Rust

use spin::Lazy;
pub static KERNEL_STATE: Lazy<spin::Mutex<KernelInternalState>> =
Lazy::new(|| spin::Mutex::new(KernelInternalState::new()));
pub struct KernelInternalState {
pub hostname: String,
should_shutdown: bool,
}
impl KernelInternalState {
pub fn new() -> Self {
Self {
should_shutdown: false,
hostname: "".to_string(),
}
}
pub fn set_hostname(&mut self, hostname: String) {
self.hostname = hostname;
}
pub fn shutdown(&mut self) {
self.should_shutdown = true;
}
pub fn update_state(&mut self) {
if self.should_shutdown {
crate::arch::shutdown();
}
}
}
impl Default for KernelInternalState {
fn default() -> Self {
Self::new()
}
}