From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v2 07/12] sys: remove lazy_static dependency
Date: Wed, 14 Aug 2024 09:19:56 +0200 [thread overview]
Message-ID: <20240814072001.53422-7-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20240814072001.53422-1-m.sandoval@proxmox.com>
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
proxmox-sys/Cargo.toml | 2 +-
proxmox-sys/src/lib.rs | 29 ++++++++++++++---------------
proxmox-sys/src/linux/procfs/mod.rs | 13 ++++---------
3 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/proxmox-sys/Cargo.toml b/proxmox-sys/Cargo.toml
index 4022228c..c5d2bd87 100644
--- a/proxmox-sys/Cargo.toml
+++ b/proxmox-sys/Cargo.toml
@@ -6,13 +6,13 @@ edition.workspace = true
license.workspace = true
repository.workspace = true
description = "System tools (using nix)."
+rust-version.workspace = true
exclude.workspace = true
[dependencies]
anyhow.workspace = true
base64.workspace = true
-lazy_static.workspace = true
libc.workspace = true
log.workspace = true
nix.workspace = true
diff --git a/proxmox-sys/src/lib.rs b/proxmox-sys/src/lib.rs
index a16b46e3..c75cd69f 100644
--- a/proxmox-sys/src/lib.rs
+++ b/proxmox-sys/src/lib.rs
@@ -2,6 +2,7 @@
use std::os::fd::{FromRawFd, OwnedFd};
use std::os::unix::ffi::OsStrExt;
+use std::sync::LazyLock;
pub mod boot_mode;
pub mod command;
@@ -20,21 +21,19 @@ pub mod systemd;
/// Returns the hosts node name (UTS node name)
pub fn nodename() -> &'static str {
- lazy_static::lazy_static! {
- static ref NODENAME: String = {
- std::str::from_utf8(
- nix::sys::utsname::uname()
- .expect("failed to get nodename")
- .nodename()
- .as_bytes(),
- )
- .expect("non utf-8 nodename not supported")
- .split('.')
- .next()
- .unwrap()
- .to_owned()
- };
- }
+ static NODENAME: LazyLock<String> = LazyLock::new(|| {
+ std::str::from_utf8(
+ nix::sys::utsname::uname()
+ .expect("failed to get nodename")
+ .nodename()
+ .as_bytes(),
+ )
+ .expect("non utf-8 nodename not supported")
+ .split('.')
+ .next()
+ .unwrap()
+ .to_owned()
+ });
&NODENAME
}
diff --git a/proxmox-sys/src/linux/procfs/mod.rs b/proxmox-sys/src/linux/procfs/mod.rs
index 6c436c74..0875fcf8 100644
--- a/proxmox-sys/src/linux/procfs/mod.rs
+++ b/proxmox-sys/src/linux/procfs/mod.rs
@@ -5,11 +5,10 @@ use std::fs::OpenOptions;
use std::io::{BufRead, BufReader};
use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
-use std::sync::RwLock;
+use std::sync::{LazyLock, RwLock};
use std::time::Instant;
use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
use nix::unistd::Pid;
use serde::Serialize;
@@ -27,9 +26,7 @@ pub fn sysconf(name: i32) -> i64 {
unsafe { sysconf(name) }
}
-lazy_static! {
- pub static ref CLOCK_TICKS: f64 = sysconf(libc::_SC_CLK_TCK) as f64;
-}
+pub static CLOCK_TICKS: LazyLock<f64> = LazyLock::new(|| sysconf(libc::_SC_CLK_TCK) as f64);
/// Selected contents of the `/proc/PID/stat` file.
pub struct PidStat {
@@ -223,10 +220,8 @@ pub struct ProcFsStat {
pub iowait_percent: f64,
}
-lazy_static! {
- static ref PROC_LAST_STAT: RwLock<(ProcFsStat, Instant, bool)> =
- RwLock::new((ProcFsStat::default(), Instant::now(), true));
-}
+static PROC_LAST_STAT: LazyLock<RwLock<(ProcFsStat, Instant, bool)>> =
+ LazyLock::new(|| RwLock::new((ProcFsStat::default(), Instant::now(), true)));
/// reads `/proc/stat`. For now only total host CPU usage is handled as the
/// other metrics are not really interesting
--
2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2024-08-14 7:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 7:19 [pbs-devel] [PATCH proxmox v2 01/12] cargo: set msrv to 1.80 Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 02/12] dns-api: remove lazy-static dependency Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 03/12] async: remove lazy_static dependency Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 04/12] subscription: " Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 05/12] rest-server: " Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 06/12] time: " Maximiliano Sandoval
2024-08-14 7:19 ` Maximiliano Sandoval [this message]
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 08/12] network-api: " Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 09/12] auth-api: " Maximiliano Sandoval
2024-08-14 7:19 ` [pbs-devel] [PATCH proxmox v2 10/12] acme-api: " Maximiliano Sandoval
2024-08-14 7:20 ` [pbs-devel] [PATCH proxmox v2 11/12] schema: " Maximiliano Sandoval
2024-08-14 7:20 ` [pbs-devel] [PATCH proxmox v2 12/12] cargo: remove lazy_static dependency on workspace Maximiliano Sandoval
2024-08-14 8:51 ` [pbs-devel] [PATCH proxmox v2 01/12] cargo: set msrv to 1.80 Wolfgang Bumiller
2024-08-14 10:04 ` [pbs-devel] applied-series: " Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240814072001.53422-7-m.sandoval@proxmox.com \
--to=m.sandoval@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox