Skip to content

Commit 104cbfa

Browse files
committed
remove useless atomic structures from locked ProcFs
1 parent 6337e9b commit 104cbfa

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

crates/kernel-impl/src/procfs.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use core::{
44
fmt::{self, Display, Write},
55
};
66

7-
use hyperion_scheduler::lock::Once;
87
use hyperion_vfs::{
98
device::{DirectoryDevice, FileDevice},
109
error::{IoError, IoResult},
@@ -26,17 +25,17 @@ pub fn init(root: impl IntoNode) {
2625

2726
pub struct ProcFs<Mut> {
2827
// TODO: doesnt have to be sync, use Option instead of Once
29-
cmdline: Once<Node<Mut>>,
30-
version: Once<Node<Mut>>,
31-
cpuinfo: Once<Node<Mut>>,
28+
cmdline: Option<Node<Mut>>,
29+
version: Option<Node<Mut>>,
30+
cpuinfo: Option<Node<Mut>>,
3231
}
3332

3433
impl<Mut: AnyMutex> ProcFs<Mut> {
3534
pub const fn new() -> Self {
3635
Self {
37-
cmdline: Once::new(),
38-
version: Once::new(),
39-
cpuinfo: Once::new(),
36+
cmdline: None,
37+
version: None,
38+
cpuinfo: None,
4039
}
4140
}
4241

@@ -50,15 +49,15 @@ impl<Mut: AnyMutex> ProcFs<Mut> {
5049
}))
5150
}
5251

53-
fn cmdline(&self) -> Node<Mut> {
52+
fn cmdline(&mut self) -> Node<Mut> {
5453
self.cmdline
55-
.call_once(|| Node::new_file(DisplayFile(hyperion_boot::args::get().cmdline)))
54+
.get_or_insert_with(|| Node::new_file(DisplayFile(hyperion_boot::args::get().cmdline)))
5655
.clone()
5756
}
5857

59-
fn version(&self) -> Node<Mut> {
58+
fn version(&mut self) -> Node<Mut> {
6059
self.version
61-
.call_once(|| {
60+
.get_or_insert_with(|| {
6261
Node::new_file(DisplayFile(format!(
6362
"{} version {} #{} {}",
6463
hyperion_kernel_info::NAME,
@@ -70,7 +69,7 @@ impl<Mut: AnyMutex> ProcFs<Mut> {
7069
.clone()
7170
}
7271

73-
fn uptime(&self) -> Node<Mut> {
72+
fn uptime(&mut self) -> Node<Mut> {
7473
Node::new_file(DisplayFile(Uptime {
7574
system_s: (hyperion_clock::get().nanosecond_now() / 10_000_000) as f32 / 100.0,
7675
cpu_idle_sum_s: hyperion_scheduler::idle()
@@ -79,9 +78,9 @@ impl<Mut: AnyMutex> ProcFs<Mut> {
7978
}))
8079
}
8180

82-
fn cpuinfo(&self) -> Node<Mut> {
81+
fn cpuinfo(&mut self) -> Node<Mut> {
8382
self.cpuinfo
84-
.call_once(|| {
83+
.get_or_insert_with(|| {
8584
let mut buf = String::new();
8685
for n in 0..hyperion_boot::cpu_count() {
8786
_ = writeln!(&mut buf, "processor : {n}");

0 commit comments

Comments
 (0)