@@ -473,7 +473,10 @@ impl Source {
473
473
// Register the current task's waker if not present already.
474
474
if w. readers . iter ( ) . all ( |w| !w. will_wake ( cx. waker ( ) ) ) {
475
475
w. readers . push ( cx. waker ( ) . clone ( ) ) ;
476
- limit_waker_list ( & mut w. readers ) ;
476
+ if limit_waker_list ( & mut w. readers ) {
477
+ self . wakers_registered
478
+ . fetch_and ( !Self :: READERS_REGISTERED , Ordering :: SeqCst ) ;
479
+ }
477
480
}
478
481
479
482
// Remember the current ticks.
@@ -527,7 +530,10 @@ impl Source {
527
530
// Register the current task's waker if not present already.
528
531
if w. writers . iter ( ) . all ( |w| !w. will_wake ( cx. waker ( ) ) ) {
529
532
w. writers . push ( cx. waker ( ) . clone ( ) ) ;
530
- limit_waker_list ( & mut w. writers ) ;
533
+ if limit_waker_list ( & mut w. writers ) {
534
+ self . wakers_registered
535
+ . fetch_and ( !Self :: WRITERS_REGISTERED , Ordering :: SeqCst ) ;
536
+ }
531
537
}
532
538
533
539
// Remember the current ticks.
@@ -549,7 +555,7 @@ impl Source {
549
555
}
550
556
}
551
557
552
- /// Wakes up all wakers in the list if it grew too big.
558
+ /// Wakes up all wakers in the list if it grew too big and returns whether it did .
553
559
///
554
560
/// The waker list keeps growing in pathological cases where a single async I/O handle has lots of
555
561
/// different reader or writer tasks. If the number of interested wakers crosses some threshold, we
@@ -562,11 +568,14 @@ impl Source {
562
568
/// However, we don't worry about such scenarios because it's very unlikely to have more than two
563
569
/// actually concurrent tasks operating on a single async I/O handle. If we happen to cross the
564
570
/// aforementioned threshold, we have bigger problems to worry about.
565
- fn limit_waker_list ( wakers : & mut Vec < Waker > ) {
571
+ fn limit_waker_list ( wakers : & mut Vec < Waker > ) -> bool {
566
572
if wakers. len ( ) > 50 {
567
573
for waker in wakers. drain ( ..) {
568
574
// Don't let a panicking waker blow everything up.
569
575
let _ = panic:: catch_unwind ( || waker. wake ( ) ) ;
570
576
}
577
+ true
578
+ } else {
579
+ false
571
580
}
572
581
}
0 commit comments