@@ -20,24 +20,23 @@ use sync::{Condvar, Mutex};
20
20
#[ cfg( any( test, feature = "std" ) ) ]
21
21
use std:: time:: Instant ;
22
22
23
- /// Used to signal to the ChannelManager persister that the manager needs to be re-persisted to
24
- /// disk/backups, through `await_persistable_update_timeout` and `await_persistable_update`.
23
+ /// Used to signal to one of many waiters that the condition they're waiting on has happened.
25
24
pub ( crate ) struct Notifier {
26
- /// Users won't access the persistence_lock directly, but rather wait on its bool using
25
+ /// Users won't access the lock directly, but rather wait on its bool using
27
26
/// `wait_timeout` and `wait`.
28
- persistence_lock : ( Mutex < bool > , Condvar ) ,
27
+ lock : ( Mutex < bool > , Condvar ) ,
29
28
}
30
29
31
30
impl Notifier {
32
31
pub ( crate ) fn new ( ) -> Self {
33
32
Self {
34
- persistence_lock : ( Mutex :: new ( false ) , Condvar :: new ( ) ) ,
33
+ lock : ( Mutex :: new ( false ) , Condvar :: new ( ) ) ,
35
34
}
36
35
}
37
36
38
37
pub ( crate ) fn wait ( & self ) {
39
38
loop {
40
- let & ( ref mtx, ref cvar) = & self . persistence_lock ;
39
+ let & ( ref mtx, ref cvar) = & self . lock ;
41
40
let mut guard = mtx. lock ( ) . unwrap ( ) ;
42
41
if * guard {
43
42
* guard = false ;
@@ -56,7 +55,7 @@ impl Notifier {
56
55
pub ( crate ) fn wait_timeout ( & self , max_wait : Duration ) -> bool {
57
56
let current_time = Instant :: now ( ) ;
58
57
loop {
59
- let & ( ref mtx, ref cvar) = & self . persistence_lock ;
58
+ let & ( ref mtx, ref cvar) = & self . lock ;
60
59
let mut guard = mtx. lock ( ) . unwrap ( ) ;
61
60
if * guard {
62
61
* guard = false ;
@@ -81,18 +80,18 @@ impl Notifier {
81
80
}
82
81
}
83
82
84
- /// Wake waiters, tracking that persistence needs to occur.
83
+ /// Wake waiters, tracking that wake needs to occur even if there are currently no waiters .
85
84
pub ( crate ) fn notify ( & self ) {
86
- let & ( ref persist_mtx, ref cnd) = & self . persistence_lock ;
87
- let mut persistence_lock = persist_mtx. lock ( ) . unwrap ( ) ;
88
- * persistence_lock = true ;
89
- mem:: drop ( persistence_lock ) ;
85
+ let & ( ref persist_mtx, ref cnd) = & self . lock ;
86
+ let mut lock = persist_mtx. lock ( ) . unwrap ( ) ;
87
+ * lock = true ;
88
+ mem:: drop ( lock ) ;
90
89
cnd. notify_all ( ) ;
91
90
}
92
91
93
92
#[ cfg( any( test, feature = "_test_utils" ) ) ]
94
- pub fn needs_persist ( & self ) -> bool {
95
- let & ( ref mtx, _) = & self . persistence_lock ;
93
+ pub fn notify_pending ( & self ) -> bool {
94
+ let & ( ref mtx, _) = & self . lock ;
96
95
let guard = mtx. lock ( ) . unwrap ( ) ;
97
96
* guard
98
97
}
@@ -115,9 +114,9 @@ mod tests {
115
114
let exit_thread_clone = exit_thread. clone ( ) ;
116
115
thread:: spawn ( move || {
117
116
loop {
118
- let & ( ref persist_mtx, ref cnd) = & thread_notifier. persistence_lock ;
119
- let mut persistence_lock = persist_mtx. lock ( ) . unwrap ( ) ;
120
- * persistence_lock = true ;
117
+ let & ( ref persist_mtx, ref cnd) = & thread_notifier. lock ;
118
+ let mut lock = persist_mtx. lock ( ) . unwrap ( ) ;
119
+ * lock = true ;
121
120
cnd. notify_all ( ) ;
122
121
123
122
if exit_thread_clone. load ( Ordering :: SeqCst ) {
0 commit comments