Skip to content

Commit 4cc2e37

Browse files
committed
fixup: use RwLock
1 parent bfd1c58 commit 4cc2e37

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/debouncer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
1414
use std::cmp::Reverse;
1515
use std::collections::{BinaryHeap, HashSet};
16-
use std::sync::Mutex;
16+
use std::sync::RwLock;
1717
use std::time::{Duration, Instant};
1818

1919
#[derive(Default)]
2020
pub(crate) struct Debouncer {
21-
state: Mutex<DebouncerState>,
21+
state: RwLock<DebouncerState>,
2222
}
2323

2424
#[derive(Default)]
@@ -76,12 +76,12 @@ impl Debouncer {
7676
/// Returns true if the token was notified recently
7777
/// and should not be notified again.
7878
pub(crate) fn is_debounced(&self, now: Instant, token: &String) -> bool {
79-
let mut state = self.state.lock().unwrap();
79+
let mut state = self.state.write().unwrap();
8080
state.is_debounced(now, token)
8181
}
8282

8383
pub(crate) fn notify(&self, now: Instant, token: String) {
84-
self.state.lock().unwrap().notify(now, token);
84+
self.state.write().unwrap().notify(now, token);
8585
}
8686

8787
/// Returns number of currently debounced notification tokens.
@@ -90,7 +90,7 @@ impl Debouncer {
9090
///
9191
/// This function does not remove expired tokens.
9292
pub(crate) fn count(&self) -> usize {
93-
self.state.lock().unwrap().count()
93+
self.state.read().unwrap().count()
9494
}
9595
}
9696

0 commit comments

Comments
 (0)