LazyLock usage

This commit is contained in:
ssrlive 2024-07-27 00:08:07 +08:00
parent 016aaa6128
commit 6567b6bc00
2 changed files with 4 additions and 6 deletions

View file

@ -8,7 +8,7 @@ homepage = "https://github.com/blechschmidt/tun2proxy"
authors = ["B. Blechschmidt", "ssrlive"] authors = ["B. Blechschmidt", "ssrlive"]
description = "Tunnel interface to proxy" description = "Tunnel interface to proxy"
readme = "README.md" readme = "README.md"
rust-version = "1.77" rust-version = "1.80"
[lib] [lib]
crate-type = ["staticlib", "cdylib", "lib"] crate-type = ["staticlib", "cdylib", "lib"]
@ -26,7 +26,6 @@ hashlink = "0.9"
hickory-proto = "0.24" hickory-proto = "0.24"
httparse = "1" httparse = "1"
ipstack = { version = "0.1" } ipstack = { version = "0.1" }
lazy_static = "1"
log = { version = "0.4", features = ["std"] } log = { version = "0.4", features = ["std"] }
percent-encoding = "2" percent-encoding = "2"
socks5-impl = { version = "0.5" } socks5-impl = { version = "0.5" }

View file

@ -1,5 +1,6 @@
use crate::error::{Error, Result}; use crate::error::{Error, Result};
use std::os::raw::c_void; use std::os::raw::c_void;
use std::sync::{LazyLock, Mutex};
/// # Safety /// # Safety
/// ///
@ -44,10 +45,8 @@ unsafe impl Sync for TrafficStatusCallback {}
static TRAFFIC_STATUS_CALLBACK: std::sync::Mutex<Option<TrafficStatusCallback>> = std::sync::Mutex::new(None); static TRAFFIC_STATUS_CALLBACK: std::sync::Mutex<Option<TrafficStatusCallback>> = std::sync::Mutex::new(None);
static SEND_INTERVAL_SECS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1); static SEND_INTERVAL_SECS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
lazy_static::lazy_static! { static TRAFFIC_STATUS: LazyLock<Mutex<TrafficStatus>> = LazyLock::new(|| Mutex::new(TrafficStatus::default()));
static ref TRAFFIC_STATUS: std::sync::Mutex<TrafficStatus> = std::sync::Mutex::new(TrafficStatus::default()); static TIME_STAMP: LazyLock<Mutex<std::time::Instant>> = LazyLock::new(|| Mutex::new(std::time::Instant::now()));
static ref TIME_STAMP: std::sync::Mutex<std::time::Instant> = std::sync::Mutex::new(std::time::Instant::now());
}
pub(crate) fn traffic_status_update(delta_tx: usize, delta_rx: usize) -> Result<()> { pub(crate) fn traffic_status_update(delta_tx: usize, delta_rx: usize) -> Result<()> {
{ {