refactor: Replace std RwLock with parking_lot

This commit is contained in:
Jade Ellis 2025-07-19 21:03:17 +01:00
commit a1d616e3e3
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
8 changed files with 54 additions and 72 deletions

View file

@ -40,7 +40,6 @@ where
self.state
.active
.read()
.expect("shared lock")
.iter()
.filter(|capture| filter(self, capture, event, &ctx))
.for_each(|capture| handle(self, capture, event, &ctx));

View file

@ -1,10 +1,11 @@
use std::sync::{Arc, RwLock};
use std::sync::Arc;
use super::Capture;
use crate::SyncRwLock;
/// Capture layer state.
pub struct State {
pub(super) active: RwLock<Vec<Arc<Capture>>>,
pub(super) active: SyncRwLock<Vec<Arc<Capture>>>,
}
impl Default for State {
@ -13,17 +14,14 @@ impl Default for State {
impl State {
#[must_use]
pub fn new() -> Self { Self { active: RwLock::new(Vec::new()) } }
pub fn new() -> Self { Self { active: SyncRwLock::new(Vec::new()) } }
pub(super) fn add(&self, capture: &Arc<Capture>) {
self.active
.write()
.expect("locked for writing")
.push(capture.clone());
self.active.write().push(capture.clone());
}
pub(super) fn del(&self, capture: &Arc<Capture>) {
let mut vec = self.active.write().expect("locked for writing");
let mut vec = self.active.write();
if let Some(pos) = vec.iter().position(|v| Arc::ptr_eq(v, capture)) {
vec.swap_remove(pos);
}