@@ -30,26 +30,26 @@ use std::pin::Pin;
30
30
31
31
/// Used to signal to one of many waiters that the condition they're waiting on has happened.
32
32
pub ( crate ) struct Notifier {
33
- persist_pending : Mutex < ( bool , Option < Arc < Mutex < FutureState > > > ) > ,
34
- persistence_condvar : Condvar ,
33
+ notify_pending : Mutex < ( bool , Option < Arc < Mutex < FutureState > > > ) > ,
34
+ condvar : Condvar ,
35
35
}
36
36
37
37
impl Notifier {
38
38
pub ( crate ) fn new ( ) -> Self {
39
39
Self {
40
- persist_pending : Mutex :: new ( ( false , None ) ) ,
41
- persistence_condvar : Condvar :: new ( ) ,
40
+ notify_pending : Mutex :: new ( ( false , None ) ) ,
41
+ condvar : Condvar :: new ( ) ,
42
42
}
43
43
}
44
44
45
45
pub ( crate ) fn wait ( & self ) {
46
46
loop {
47
- let mut guard = self . persist_pending . lock ( ) . unwrap ( ) ;
47
+ let mut guard = self . notify_pending . lock ( ) . unwrap ( ) ;
48
48
if guard. 0 {
49
49
guard. 0 = false ;
50
50
return ;
51
51
}
52
- guard = self . persistence_condvar . wait ( guard) . unwrap ( ) ;
52
+ guard = self . condvar . wait ( guard) . unwrap ( ) ;
53
53
let result = guard. 0 ;
54
54
if result {
55
55
guard. 0 = false ;
@@ -62,12 +62,12 @@ impl Notifier {
62
62
pub ( crate ) fn wait_timeout ( & self , max_wait : Duration ) -> bool {
63
63
let current_time = Instant :: now ( ) ;
64
64
loop {
65
- let mut guard = self . persist_pending . lock ( ) . unwrap ( ) ;
65
+ let mut guard = self . notify_pending . lock ( ) . unwrap ( ) ;
66
66
if guard. 0 {
67
67
guard. 0 = false ;
68
68
return true ;
69
69
}
70
- guard = self . persistence_condvar . wait_timeout ( guard, max_wait) . unwrap ( ) . 0 ;
70
+ guard = self . condvar . wait_timeout ( guard, max_wait) . unwrap ( ) . 0 ;
71
71
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
72
72
// desired wait time has actually passed, and if not then restart the loop with a reduced wait
73
73
// time. Note that this logic can be highly simplified through the use of
@@ -88,40 +88,40 @@ impl Notifier {
88
88
89
89
/// Wake waiters, tracking that persistence needs to occur.
90
90
pub ( crate ) fn notify ( & self ) {
91
- let mut persistence_lock = self . persist_pending . lock ( ) . unwrap ( ) ;
92
- persistence_lock . 0 = true ;
93
- if let Some ( future_state) = persistence_lock . 1 . take ( ) {
91
+ let mut lock = self . notify_pending . lock ( ) . unwrap ( ) ;
92
+ lock . 0 = true ;
93
+ if let Some ( future_state) = lock . 1 . take ( ) {
94
94
future_state. lock ( ) . unwrap ( ) . complete ( ) ;
95
95
}
96
- mem:: drop ( persistence_lock ) ;
97
- self . persistence_condvar . notify_all ( ) ;
96
+ mem:: drop ( lock ) ;
97
+ self . condvar . notify_all ( ) ;
98
98
}
99
99
100
100
/// Gets a [`Future`] that will get woken up with any waiters
101
101
pub ( crate ) fn get_future ( & self ) -> Future {
102
- let mut persistence_lock = self . persist_pending . lock ( ) . unwrap ( ) ;
103
- if persistence_lock . 0 {
102
+ let mut lock = self . notify_pending . lock ( ) . unwrap ( ) ;
103
+ if lock . 0 {
104
104
Future {
105
105
state : Arc :: new ( Mutex :: new ( FutureState {
106
106
callbacks : Vec :: new ( ) ,
107
107
complete : false ,
108
108
} ) )
109
109
}
110
- } else if let Some ( existing_state) = & persistence_lock . 1 {
110
+ } else if let Some ( existing_state) = & lock . 1 {
111
111
Future { state : Arc :: clone ( & existing_state) }
112
112
} else {
113
113
let state = Arc :: new ( Mutex :: new ( FutureState {
114
114
callbacks : Vec :: new ( ) ,
115
115
complete : false ,
116
116
} ) ) ;
117
- persistence_lock . 1 = Some ( Arc :: clone ( & state) ) ;
117
+ lock . 1 = Some ( Arc :: clone ( & state) ) ;
118
118
Future { state }
119
119
}
120
120
}
121
121
122
122
#[ cfg( any( test, feature = "_test_utils" ) ) ]
123
123
pub fn needs_persist ( & self ) -> bool {
124
- self . persist_pending . lock ( ) . unwrap ( ) . 0
124
+ self . notify_pending . lock ( ) . unwrap ( ) . 0
125
125
}
126
126
}
127
127
@@ -214,9 +214,9 @@ mod tests {
214
214
let exit_thread_clone = exit_thread. clone ( ) ;
215
215
thread:: spawn ( move || {
216
216
loop {
217
- let mut persistence_lock = thread_notifier. persist_pending . lock ( ) . unwrap ( ) ;
218
- persistence_lock . 0 = true ;
219
- thread_notifier. persistence_condvar . notify_all ( ) ;
217
+ let mut lock = thread_notifier. notify_pending . lock ( ) . unwrap ( ) ;
218
+ lock . 0 = true ;
219
+ thread_notifier. condvar . notify_all ( ) ;
220
220
221
221
if exit_thread_clone. load ( Ordering :: SeqCst ) {
222
222
break
0 commit comments