irontide_core/live_guard.rs
1use std::sync::Arc;
2use std::sync::atomic::{AtomicUsize, Ordering};
3
4/// M224 D3: RAII counter increment for the global connection cap. Wraps
5/// `Arc<AtomicUsize>` so the live count cannot leak even if the listener/admit
6/// loop panics or drops a connection mid-pipeline.
7/// dropped automatically when the owning connection is dropped or forwarded.
8#[derive(Debug)]
9pub struct LiveConnectionGuard {
10 counter: Arc<AtomicUsize>,
11}
12
13impl LiveConnectionGuard {
14 /// Create a new guard and increment the backing counter atomically.
15 pub fn new(counter: Arc<AtomicUsize>) -> Self {
16 counter.fetch_add(1, Ordering::SeqCst);
17 Self { counter }
18 }
19}
20
21impl Drop for LiveConnectionGuard {
22 fn drop(&mut self) {
23 self.counter.fetch_sub(1, Ordering::SeqCst);
24 }
25}