Browse Source

LazyLock usage

pull/141/head
ssrlive 2 years ago
parent
commit
6567b6bc00
  1. 3
      Cargo.toml
  2. 7
      src/traffic_status.rs

3
Cargo.toml

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

7
src/traffic_status.rs

@ -1,5 +1,6 @@
use crate::error::{Error, Result};
use std::os::raw::c_void;
use std::sync::{LazyLock, Mutex};
/// # 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 SEND_INTERVAL_SECS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
lazy_static::lazy_static! {
static ref TRAFFIC_STATUS: std::sync::Mutex<TrafficStatus> = std::sync::Mutex::new(TrafficStatus::default());
static ref TIME_STAMP: std::sync::Mutex<std::time::Instant> = std::sync::Mutex::new(std::time::Instant::now());
}
static TRAFFIC_STATUS: LazyLock<Mutex<TrafficStatus>> = LazyLock::new(|| Mutex::new(TrafficStatus::default()));
static TIME_STAMP: LazyLock<Mutex<std::time::Instant>> = LazyLock::new(|| Mutex::new(std::time::Instant::now()));
pub(crate) fn traffic_status_update(delta_tx: usize, delta_rx: usize) -> Result<()> {
{

Loading…
Cancel
Save