From 374a2b04c49cf61f9fab93b8fb23c4d211d7b1cf Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 31 Jan 2024 17:47:27 +0000 Subject: [PATCH] fix(YIELD_TO_EXECUTOR_IF_READY_ON_FIRST_POLL): it always yieled, even at higher poll count --- tokio-epoll-uring/src/system/slots.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tokio-epoll-uring/src/system/slots.rs b/tokio-epoll-uring/src/system/slots.rs index e2ae935..9d9ad12 100644 --- a/tokio-epoll-uring/src/system/slots.rs +++ b/tokio-epoll-uring/src/system/slots.rs @@ -502,7 +502,9 @@ impl SlotHandle { NeedToWait, ShutDown, } + let mut poll_count = 0; let inspect_slot_res = poll_fn(|cx| { + poll_count += 1; let inspect_slot_res = slot.slots_weak.try_upgrade_mut(move |inner| { let storage = &mut inner.storage; let slot_storage_ref = &mut storage[slot.idx]; @@ -538,13 +540,14 @@ impl SlotHandle { } }) .await; - let res: i32; - let was_ready_on_first_poll: bool; - match inspect_slot_res { - InspectSlotResult::AlreadyDone(r) => { - res = r; - was_ready_on_first_poll = true; - } + assert!(poll_count >= 1); + assert!( + !matches!(inspect_slot_res, InspectSlotResult::NeedToWait), + "poll_fn closure returns Pending in that case" + ); + + let res = match inspect_slot_res { + InspectSlotResult::AlreadyDone(r) => r, InspectSlotResult::NeedToWait => { unreachable!() } @@ -564,8 +567,7 @@ impl SlotHandle { } }; - if was_ready_on_first_poll && *crate::env_tunables::YIELD_TO_EXECUTOR_IF_READY_ON_FIRST_POLL - { + if poll_count == 1 && *crate::env_tunables::YIELD_TO_EXECUTOR_IF_READY_ON_FIRST_POLL { tokio::task::yield_now().await; }