@@ -77,7 +77,7 @@ use std::os::windows::io::{AsRawSocket, FromRawSocket, RawSocket};
77
77
78
78
use futures_lite:: io:: { AsyncRead , AsyncWrite } ;
79
79
use futures_lite:: stream:: { self , Stream } ;
80
- use futures_lite:: { future, pin, ready } ;
80
+ use futures_lite:: { future, pin} ;
81
81
82
82
use crate :: reactor:: { Reactor , Source } ;
83
83
@@ -575,7 +575,6 @@ impl<T> Async<T> {
575
575
pub async fn read_with < R > ( & self , op : impl FnMut ( & T ) -> io:: Result < R > ) -> io:: Result < R > {
576
576
let mut op = op;
577
577
loop {
578
- future:: poll_fn ( |cx| maybe_yield ( cx) ) . await ;
579
578
match op ( self . get_ref ( ) ) {
580
579
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
581
580
res => return res,
@@ -612,7 +611,6 @@ impl<T> Async<T> {
612
611
) -> io:: Result < R > {
613
612
let mut op = op;
614
613
loop {
615
- future:: poll_fn ( |cx| maybe_yield ( cx) ) . await ;
616
614
match op ( self . get_mut ( ) ) {
617
615
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
618
616
res => return res,
@@ -711,7 +709,6 @@ impl<T: Read> AsyncRead for Async<T> {
711
709
cx : & mut Context < ' _ > ,
712
710
buf : & mut [ u8 ] ,
713
711
) -> Poll < io:: Result < usize > > {
714
- ready ! ( maybe_yield( cx) ) ;
715
712
match ( & mut * self ) . get_mut ( ) . read ( buf) {
716
713
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
717
714
res => return Poll :: Ready ( res) ,
@@ -725,7 +722,6 @@ impl<T: Read> AsyncRead for Async<T> {
725
722
cx : & mut Context < ' _ > ,
726
723
bufs : & mut [ IoSliceMut < ' _ > ] ,
727
724
) -> Poll < io:: Result < usize > > {
728
- ready ! ( maybe_yield( cx) ) ;
729
725
match ( & mut * self ) . get_mut ( ) . read_vectored ( bufs) {
730
726
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
731
727
res => return Poll :: Ready ( res) ,
@@ -744,7 +740,6 @@ where
744
740
cx : & mut Context < ' _ > ,
745
741
buf : & mut [ u8 ] ,
746
742
) -> Poll < io:: Result < usize > > {
747
- ready ! ( maybe_yield( cx) ) ;
748
743
match ( & * self ) . get_ref ( ) . read ( buf) {
749
744
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
750
745
res => return Poll :: Ready ( res) ,
@@ -758,7 +753,6 @@ where
758
753
cx : & mut Context < ' _ > ,
759
754
bufs : & mut [ IoSliceMut < ' _ > ] ,
760
755
) -> Poll < io:: Result < usize > > {
761
- ready ! ( maybe_yield( cx) ) ;
762
756
match ( & * self ) . get_ref ( ) . read_vectored ( bufs) {
763
757
Err ( err) if err. kind ( ) == io:: ErrorKind :: WouldBlock => { }
764
758
res => return Poll :: Ready ( res) ,
@@ -1486,17 +1480,3 @@ async fn optimistic(fut: impl Future<Output = io::Result<()>>) -> io::Result<()>
1486
1480
} )
1487
1481
. await
1488
1482
}
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