use std::sync::atomic::{AtomicU64, Ordering};
static ACTIVE_CONNECTIONS: AtomicU64 = AtomicU64::new(0);
pub(super) struct ActiveConnection;
impl ActiveConnection {
pub(super) fn new() -> Self {
ACTIVE_CONNECTIONS.fetch_add(1, Ordering::Relaxed);
crate::metrics::inc_connections();
Self
}
}
impl Drop for ActiveConnection {
fn drop(&mut self) {
ACTIVE_CONNECTIONS.fetch_sub(1, Ordering::Relaxed);
crate::metrics::dec_connections();
}
}
#[must_use]
pub fn active_connection_count() -> u64 { ACTIVE_CONNECTIONS.load(Ordering::Relaxed) }
pub(super) fn current_count() -> u64 { ACTIVE_CONNECTIONS.load(Ordering::Relaxed) }