Skip to content

Commit 5c740bc

Browse files
committed
Make the Waitlist responsible for calling wake
This api is harder to misuse, as one cannot forget to call wake after pop.
1 parent 3b79b05 commit 5c740bc

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/conn/pool/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ impl Pool {
229229
.connection_count
230230
.store(exchange.exist, atomic::Ordering::Relaxed);
231231
// we just enabled the creation of a new connection!
232-
if let Some(w) = exchange.waiting.pop() {
233-
w.wake();
234-
}
232+
exchange.waiting.wake();
235233
}
236234

237235
/// Poll the pool for an available connection.

src/conn/pool/recycler.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ impl Recycler {
8181
.metrics
8282
.connections_in_pool
8383
.store(exchange.available.len(), Ordering::Relaxed);
84-
if let Some(w) = exchange.waiting.pop() {
85-
w.wake();
86-
}
84+
exchange.waiting.wake();
8785
}
8886
}
8987
}
@@ -244,9 +242,7 @@ impl Future for Recycler {
244242
.connection_count
245243
.store(exchange.exist, Ordering::Relaxed);
246244
for _ in 0..self.discarded {
247-
if let Some(w) = exchange.waiting.pop() {
248-
w.wake();
249-
}
245+
exchange.waiting.wake();
250246
}
251247
drop(exchange);
252248
self.discarded = 0;
@@ -282,9 +278,7 @@ impl Future for Recycler {
282278
if self.inner.closed.load(Ordering::Acquire) {
283279
// `DisconnectPool` might still wait to be woken up.
284280
let mut exchange = self.inner.exchange.lock().unwrap();
285-
while let Some(w) = exchange.waiting.pop() {
286-
w.wake();
287-
}
281+
while exchange.waiting.wake() {}
288282
// we're about to exit, so there better be no outstanding connections
289283
assert_eq!(exchange.exist, 0);
290284
assert_eq!(exchange.available.len(), 0);

src/conn/pool/waitlist.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ impl Waitlist {
4848
!occupied
4949
}
5050

51-
pub(crate) fn pop(&mut self) -> Option<Waker> {
51+
/// Returns `true` if anyone was awaken
52+
pub(crate) fn wake(&mut self) -> bool {
5253
match self.queue.pop() {
5354
Some((qw, _)) => {
5455
self.metrics
5556
.active_wait_requests
5657
.fetch_sub(1, atomic::Ordering::Relaxed);
57-
Some(qw.waker)
58+
qw.waker.wake();
59+
true
5860
}
59-
None => None,
61+
None => false,
6062
}
6163
}
6264

0 commit comments

Comments
 (0)