mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-12-17 20:58:58 -05:00
tracing capture interface
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1bb4021b90
commit
aa34021b27
15 changed files with 284 additions and 27 deletions
35
src/core/log/capture/state.rs
Normal file
35
src/core/log/capture/state.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use super::Capture;
|
||||
|
||||
/// Capture layer state.
|
||||
pub struct State {
|
||||
pub(super) active: RwLock<Vec<Arc<Capture>>>,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl State {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
active: RwLock::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn add(&self, capture: &Arc<Capture>) {
|
||||
self.active
|
||||
.write()
|
||||
.expect("locked for writing")
|
||||
.push(capture.clone());
|
||||
}
|
||||
|
||||
pub(super) fn del(&self, capture: &Arc<Capture>) {
|
||||
let mut vec = self.active.write().expect("locked for writing");
|
||||
if let Some(pos) = vec.iter().position(|v| Arc::ptr_eq(v, capture)) {
|
||||
vec.swap_remove(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue