Skip to content

Commit 4e7cdb6

Browse files
author
Stjepan Glavina
committed
Remove random yielding
1 parent c7e7fa8 commit 4e7cdb6

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

src/lib.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use std::os::windows::io::{AsRawSocket, FromRawSocket, RawSocket};
7777

7878
use futures_lite::io::{AsyncRead, AsyncWrite};
7979
use futures_lite::stream::{self, Stream};
80-
use futures_lite::{future, pin, ready};
80+
use futures_lite::{future, pin};
8181

8282
use crate::reactor::{Reactor, Source};
8383

@@ -575,7 +575,6 @@ impl<T> Async<T> {
575575
pub async fn read_with<R>(&self, op: impl FnMut(&T) -> io::Result<R>) -> io::Result<R> {
576576
let mut op = op;
577577
loop {
578-
future::poll_fn(|cx| maybe_yield(cx)).await;
579578
match op(self.get_ref()) {
580579
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
581580
res => return res,
@@ -612,7 +611,6 @@ impl<T> Async<T> {
612611
) -> io::Result<R> {
613612
let mut op = op;
614613
loop {
615-
future::poll_fn(|cx| maybe_yield(cx)).await;
616614
match op(self.get_mut()) {
617615
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
618616
res => return res,
@@ -711,7 +709,6 @@ impl<T: Read> AsyncRead for Async<T> {
711709
cx: &mut Context<'_>,
712710
buf: &mut [u8],
713711
) -> Poll<io::Result<usize>> {
714-
ready!(maybe_yield(cx));
715712
match (&mut *self).get_mut().read(buf) {
716713
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
717714
res => return Poll::Ready(res),
@@ -725,7 +722,6 @@ impl<T: Read> AsyncRead for Async<T> {
725722
cx: &mut Context<'_>,
726723
bufs: &mut [IoSliceMut<'_>],
727724
) -> Poll<io::Result<usize>> {
728-
ready!(maybe_yield(cx));
729725
match (&mut *self).get_mut().read_vectored(bufs) {
730726
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
731727
res => return Poll::Ready(res),
@@ -744,7 +740,6 @@ where
744740
cx: &mut Context<'_>,
745741
buf: &mut [u8],
746742
) -> Poll<io::Result<usize>> {
747-
ready!(maybe_yield(cx));
748743
match (&*self).get_ref().read(buf) {
749744
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
750745
res => return Poll::Ready(res),
@@ -758,7 +753,6 @@ where
758753
cx: &mut Context<'_>,
759754
bufs: &mut [IoSliceMut<'_>],
760755
) -> Poll<io::Result<usize>> {
761-
ready!(maybe_yield(cx));
762756
match (&*self).get_ref().read_vectored(bufs) {
763757
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
764758
res => return Poll::Ready(res),
@@ -1486,17 +1480,3 @@ async fn optimistic(fut: impl Future<Output = io::Result<()>>) -> io::Result<()>
14861480
})
14871481
.await
14881482
}
1489-
1490-
/// Yields with some small probability.
1491-
///
1492-
/// If a task is doing a lot of I/O and never gets blocked on it, it may keep the executor busy
1493-
/// forever without giving other tasks a chance to run. To prevent this kind of task starvation,
1494-
/// I/O operations yield randomly even if they are ready.
1495-
fn maybe_yield(cx: &mut Context<'_>) -> Poll<()> {
1496-
if fastrand::usize(..100) == 0 {
1497-
cx.waker().wake_by_ref();
1498-
Poll::Pending
1499-
} else {
1500-
Poll::Ready(())
1501-
}
1502-
}

0 commit comments

Comments
 (0)