Skip to content

Commit 4cfa72f

Browse files
committed
f rebase
1 parent 3c3ab16 commit 4cfa72f

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lightning/src/util/wakers.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ use std::pin::Pin;
3030

3131
/// Used to signal to one of many waiters that the condition they're waiting on has happened.
3232
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,
3535
}
3636

3737
impl Notifier {
3838
pub(crate) fn new() -> Self {
3939
Self {
40-
persist_pending: Mutex::new((false, None)),
41-
persistence_condvar: Condvar::new(),
40+
notify_pending: Mutex::new((false, None)),
41+
condvar: Condvar::new(),
4242
}
4343
}
4444

4545
pub(crate) fn wait(&self) {
4646
loop {
47-
let mut guard = self.persist_pending.lock().unwrap();
47+
let mut guard = self.notify_pending.lock().unwrap();
4848
if guard.0 {
4949
guard.0 = false;
5050
return;
5151
}
52-
guard = self.persistence_condvar.wait(guard).unwrap();
52+
guard = self.condvar.wait(guard).unwrap();
5353
let result = guard.0;
5454
if result {
5555
guard.0 = false;
@@ -62,12 +62,12 @@ impl Notifier {
6262
pub(crate) fn wait_timeout(&self, max_wait: Duration) -> bool {
6363
let current_time = Instant::now();
6464
loop {
65-
let mut guard = self.persist_pending.lock().unwrap();
65+
let mut guard = self.notify_pending.lock().unwrap();
6666
if guard.0 {
6767
guard.0 = false;
6868
return true;
6969
}
70-
guard = self.persistence_condvar.wait_timeout(guard, max_wait).unwrap().0;
70+
guard = self.condvar.wait_timeout(guard, max_wait).unwrap().0;
7171
// Due to spurious wakeups that can happen on `wait_timeout`, here we need to check if the
7272
// desired wait time has actually passed, and if not then restart the loop with a reduced wait
7373
// time. Note that this logic can be highly simplified through the use of
@@ -88,40 +88,40 @@ impl Notifier {
8888

8989
/// Wake waiters, tracking that persistence needs to occur.
9090
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() {
9494
future_state.lock().unwrap().complete();
9595
}
96-
mem::drop(persistence_lock);
97-
self.persistence_condvar.notify_all();
96+
mem::drop(lock);
97+
self.condvar.notify_all();
9898
}
9999

100100
/// Gets a [`Future`] that will get woken up with any waiters
101101
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 {
104104
Future {
105105
state: Arc::new(Mutex::new(FutureState {
106106
callbacks: Vec::new(),
107107
complete: false,
108108
}))
109109
}
110-
} else if let Some(existing_state) = &persistence_lock.1 {
110+
} else if let Some(existing_state) = &lock.1 {
111111
Future { state: Arc::clone(&existing_state) }
112112
} else {
113113
let state = Arc::new(Mutex::new(FutureState {
114114
callbacks: Vec::new(),
115115
complete: false,
116116
}));
117-
persistence_lock.1 = Some(Arc::clone(&state));
117+
lock.1 = Some(Arc::clone(&state));
118118
Future { state }
119119
}
120120
}
121121

122122
#[cfg(any(test, feature = "_test_utils"))]
123123
pub fn needs_persist(&self) -> bool {
124-
self.persist_pending.lock().unwrap().0
124+
self.notify_pending.lock().unwrap().0
125125
}
126126
}
127127

@@ -214,9 +214,9 @@ mod tests {
214214
let exit_thread_clone = exit_thread.clone();
215215
thread::spawn(move || {
216216
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();
220220

221221
if exit_thread_clone.load(Ordering::SeqCst) {
222222
break

0 commit comments

Comments
 (0)