In lqosd, replace lazy_static with once_cell, per Rust best practices

These days the Rust team are recommending "once_cell", which has
simpler syntax and does the same thing.
This commit is contained in:
Herbert Wolverson
2023-03-03 20:26:14 +00:00
parent 99dc9fc066
commit 42c2c63f55
3 changed files with 4 additions and 7 deletions

2
src/rust/Cargo.lock generated
View File

@@ -1436,7 +1436,6 @@ dependencies = [
"anyhow",
"env_logger",
"jemallocator",
"lazy_static",
"log",
"lqos_bus",
"lqos_config",
@@ -1444,6 +1443,7 @@ dependencies = [
"lqos_sys",
"lqos_utils",
"nix",
"once_cell",
"parking_lot",
"rayon",
"serde",

View File

@@ -14,7 +14,7 @@ lqos_sys = { path = "../lqos_sys" }
lqos_queue_tracker = { path = "../lqos_queue_tracker" }
lqos_utils = { path = "../lqos_utils" }
tokio = { version = "1", features = [ "full", "parking_lot" ] }
lazy_static = "1.4"
once_cell = "1.17.1"
parking_lot = "0.12"
lqos_bus = { path = "../lqos_bus" }
signal-hook = "0.3"

View File

@@ -1,20 +1,17 @@
mod throughput_entry;
mod tracking_data;
use crate::throughput_tracker::tracking_data::ThroughputTracker;
use lazy_static::*;
use log::{info, warn};
use lqos_bus::{BusResponse, IpStats, TcHandle, XdpPpingResult};
use lqos_sys::XdpIpAddress;
use lqos_utils::{fdtimer::periodic, unix_time::time_since_boot};
use once_cell::sync::Lazy;
use parking_lot::RwLock;
use std::time::Duration;
const RETIRE_AFTER_SECONDS: u64 = 30;
lazy_static! {
static ref THROUGHPUT_TRACKER: RwLock<ThroughputTracker> =
RwLock::new(ThroughputTracker::new());
}
static THROUGHPUT_TRACKER: Lazy<RwLock<ThroughputTracker>> = Lazy::new(|| RwLock::new(ThroughputTracker::new()));
pub fn spawn_throughput_monitor() {
info!("Starting the bandwidth monitor thread.");