2022-04-11 15:51:54 -05:00
|
|
|
use spin::Lazy;
|
2022-01-13 08:54:33 -06:00
|
|
|
|
2022-04-11 15:51:54 -05:00
|
|
|
pub static KERNEL_STATE: Lazy<spin::Mutex<KernelInternalState>> =
|
|
|
|
Lazy::new(|| spin::Mutex::new(KernelInternalState::new()));
|
2022-01-13 08:54:33 -06:00
|
|
|
|
|
|
|
pub struct KernelInternalState {
|
2022-02-19 07:17:44 -06:00
|
|
|
pub hostname: String,
|
2022-01-13 08:54:33 -06:00
|
|
|
should_shutdown: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl KernelInternalState {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
should_shutdown: false,
|
2022-01-27 01:37:12 -06:00
|
|
|
hostname: "".to_string(),
|
2022-01-13 08:54:33 -06:00
|
|
|
}
|
|
|
|
}
|
2022-01-27 01:37:12 -06:00
|
|
|
|
|
|
|
pub fn set_hostname(&mut self, hostname: String) {
|
|
|
|
self.hostname = hostname;
|
|
|
|
}
|
2022-01-13 08:54:33 -06:00
|
|
|
pub fn shutdown(&mut self) {
|
|
|
|
self.should_shutdown = true;
|
|
|
|
}
|
|
|
|
pub fn update_state(&mut self) {
|
|
|
|
if self.should_shutdown {
|
|
|
|
crate::arch::shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 16:07:01 -05:00
|
|
|
|
|
|
|
impl Default for KernelInternalState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|