mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-10 22:52:50 +02:00
refactor: Replace std RwLock with parking_lot
This commit is contained in:
parent
30a8c06fd9
commit
a1d616e3e3
8 changed files with 54 additions and 72 deletions
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue