@@ -73,10 +73,11 @@ use std::ptr::{self, NonNull};
7373use std:: sync:: atomic:: { self , AtomicPtr , AtomicUsize , Ordering } ;
7474use std:: sync:: { Arc , Mutex , MutexGuard } ;
7575use std:: task:: { Context , Poll , Waker } ;
76- use std:: thread:: { self , Thread } ;
7776use std:: time:: { Duration , Instant } ;
7877use std:: usize;
7978
79+ use parking:: Unparker ;
80+
8081/// Inner state of [`Event`].
8182struct Inner {
8283 /// The number of notified entries, or `usize::MAX` if all of them have been notified.
@@ -598,6 +599,7 @@ impl EventListener {
598599 None => unreachable ! ( "cannot wait twice on an `EventListener`" ) ,
599600 Some ( entry) => entry,
600601 } ;
602+ let ( parker, unparker) = parking:: pair ( ) ;
601603
602604 // Set this listener's state to `Waiting`.
603605 {
@@ -612,14 +614,14 @@ impl EventListener {
612614 return true ;
613615 }
614616 // Otherwise, set the state to `Waiting`.
615- _ => e. state . set ( State :: Waiting ( thread :: current ( ) ) ) ,
617+ _ => e. state . set ( State :: Waiting ( unparker ) ) ,
616618 }
617619 }
618620
619621 // Wait until a notification is received or the timeout is reached.
620622 loop {
621623 match deadline {
622- None => thread :: park ( ) ,
624+ None => parker . park ( ) ,
623625
624626 Some ( deadline) => {
625627 // Check for timeout.
@@ -634,7 +636,7 @@ impl EventListener {
634636 }
635637
636638 // Park until the deadline.
637- thread :: park_timeout ( deadline - now) ;
639+ parker . park_timeout ( deadline - now) ;
638640 }
639641 }
640642
@@ -776,7 +778,7 @@ enum State {
776778 Polling ( Waker ) ,
777779
778780 /// A thread is blocked on it.
779- Waiting ( Thread ) ,
781+ Waiting ( Unparker ) ,
780782}
781783
782784impl State {
@@ -792,7 +794,7 @@ impl State {
792794
793795/// An entry representing a registered listener.
794796struct Entry {
795- /// THe state of this listener.
797+ /// The state of this listener.
796798 state : Cell < State > ,
797799
798800 /// Previous entry in the linked list.
@@ -928,7 +930,9 @@ impl List {
928930 State :: Notified ( _) => { }
929931 State :: Created => { }
930932 State :: Polling ( w) => w. wake ( ) ,
931- State :: Waiting ( t) => t. unpark ( ) ,
933+ State :: Waiting ( t) => {
934+ t. unpark ( ) ;
935+ }
932936 }
933937
934938 // Update the counter.
@@ -957,7 +961,9 @@ impl List {
957961 State :: Notified ( _) => { }
958962 State :: Created => { }
959963 State :: Polling ( w) => w. wake ( ) ,
960- State :: Waiting ( t) => t. unpark ( ) ,
964+ State :: Waiting ( t) => {
965+ t. unpark ( ) ;
966+ }
961967 }
962968
963969 // Update the counter.
0 commit comments