1313
1414use std:: cmp:: Reverse ;
1515use std:: collections:: { BinaryHeap , HashSet } ;
16- use std:: sync:: Mutex ;
16+ use std:: sync:: RwLock ;
1717use std:: time:: { Duration , Instant } ;
1818
1919#[ derive( Default ) ]
2020pub ( 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