Fix un-needed wakeups for unready future (#462)

This commit is contained in:
Nikolay Kim 2024-11-10 14:41:51 +05:00 committed by GitHub
parent 0a376457f1
commit 5700a50f56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 14 deletions

View file

@ -1,5 +1,9 @@
# Changes
## [3.3.2] - 2024-11-10
* Fix un-needed wakeups for unready future
## [3.3.1] - 2024-11-04
* Optimize readiness handling

View file

@ -1,6 +1,6 @@
[package]
name = "ntex-service"
version = "3.3.1"
version = "3.3.2"
authors = ["ntex contributors <team@ntex.rs>"]
description = "ntex service"
keywords = ["network", "framework", "async", "futures"]

View file

@ -19,10 +19,6 @@ pub(crate) struct WaitersRef {
impl WaitersRef {
pub(crate) fn new() -> (u32, Self) {
let mut waiters = slab::Slab::new();
// first insert for wake ups from services
let _ = waiters.insert(None);
(
waiters.insert(Default::default()) as u32,
WaitersRef {
@ -66,11 +62,6 @@ impl WaitersRef {
self.get()[idx as usize] = Some(cx.waker().clone());
}
pub(crate) fn register_unready(&self, cx: &mut Context<'_>) {
self.get()[0] = Some(cx.waker().clone());
self.get_wakers().push(0);
}
pub(crate) fn notify(&self) {
let wakers = self.get_wakers();
if !wakers.is_empty() {

View file

@ -464,10 +464,7 @@ where
}
let fut = slf.fut.as_mut().unwrap();
match unsafe { Pin::new_unchecked(fut) }.poll(cx) {
Poll::Pending => {
slf.pl.state.waiters.register_unready(cx);
Poll::Pending
}
Poll::Pending => Poll::Pending,
Poll::Ready(res) => {
let _ = slf.fut.take();
slf.pl.state.waiters.notify();