refactor: add ArcMutex/ArcRwLock type aliases
Replace repeated Arc> and Arc> with concise type aliases for readability.
This commit is contained in:
4 files changed
+17
-13
No files matched your search
+4
-3
@@ -1,7 +1,8 @@
|
||||
use crate::SHUTDOWN;
|
||||
use crate::Config;
|
||||
use crate::SHUTDOWN;
|
||||
use crate::metrics::{Metric, MetricsSender};
|
||||
use crate::pinger::PingReply;
|
||||
use crate::util::ArcMutex;
|
||||
use crate::util::MutexExt;
|
||||
use log::info;
|
||||
use std::collections::HashMap;
|
||||
@@ -20,8 +21,8 @@ pub struct ReflectorStats {
|
||||
|
||||
pub struct Baseliner {
|
||||
pub config: Config,
|
||||
pub owd_baseline: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
pub owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
pub owd_baseline: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
pub owd_recent: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
pub reselect_trigger: Sender<bool>,
|
||||
pub start_time: Instant,
|
||||
pub stats_rx: Receiver<PingReply>,
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::SHUTDOWN;
|
||||
use crate::metrics::{Metric, MetricsSender};
|
||||
use crate::netlink::{Netlink, NetlinkError, Qdisc};
|
||||
use crate::time::Time;
|
||||
use crate::util::{MutexExt, RwLockExt};
|
||||
use crate::util::{ArcMutex, ArcRwLock, MutexExt, RwLockExt};
|
||||
use crate::{Config, ReflectorStats};
|
||||
use log::{debug, info, warn};
|
||||
use rustix::thread::ClockId;
|
||||
@@ -104,9 +104,9 @@ impl State {
|
||||
pub struct Ratecontroller {
|
||||
config: Config,
|
||||
down_direction: StatsDirection,
|
||||
owd_baseline: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
|
||||
owd_baseline: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
owd_recent: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
reflectors_lock: ArcRwLock<Vec<IpAddr>>,
|
||||
reselect_trigger: Sender<bool>,
|
||||
state_dl: State,
|
||||
state_ul: State,
|
||||
@@ -244,9 +244,9 @@ impl Ratecontroller {
|
||||
|
||||
pub fn new(
|
||||
config: Config,
|
||||
owd_baseline: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
reflectors_lock: Arc<RwLock<Vec<IpAddr>>>,
|
||||
owd_baseline: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
owd_recent: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
reflectors_lock: ArcRwLock<Vec<IpAddr>>,
|
||||
reselect_trigger: Sender<bool>,
|
||||
down_direction: StatsDirection,
|
||||
up_direction: StatsDirection,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::SHUTDOWN;
|
||||
use crate::metrics::{Metric, MetricsSender};
|
||||
use crate::util::{MutexExt, RwLockExt};
|
||||
use crate::util::{ArcMutex, MutexExt, RwLockExt};
|
||||
use crate::{Config, ReflectorStats};
|
||||
use log::{debug, info};
|
||||
use std::collections::HashMap;
|
||||
@@ -13,7 +13,7 @@ use std::time::Duration;
|
||||
|
||||
pub struct ReflectorSelector {
|
||||
pub config: Config,
|
||||
pub owd_recent: Arc<Mutex<HashMap<IpAddr, ReflectorStats>>>,
|
||||
pub owd_recent: ArcMutex<HashMap<IpAddr, ReflectorStats>>,
|
||||
pub reflector_peers_lock: Arc<RwLock<Vec<IpAddr>>>,
|
||||
pub reflector_pool: Vec<IpAddr>,
|
||||
pub trigger_channel: Receiver<bool>,
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
use anyhow::anyhow;
|
||||
use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use std::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
pub type ArcMutex<T> = Arc<Mutex<T>>;
|
||||
pub type ArcRwLock<T> = Arc<RwLock<T>>;
|
||||
|
||||
pub trait MutexExt<T> {
|
||||
fn lock_anyhow(&self) -> anyhow::Result<MutexGuard<'_, T>>;
|
||||
|
||||
Reference in new issue
Block a user