@@ -13,6 +13,7 @@ use std::{
1313
1414use compio_buf:: BufResult ;
1515use compio_log:: { instrument, trace} ;
16+ use flume:: { Receiver , Sender } ;
1617use windows_sys:: Win32 :: {
1718 Foundation :: { ERROR_CANCELLED , HANDLE } ,
1819 System :: IO :: OVERLAPPED ,
@@ -396,6 +397,8 @@ pub(crate) struct Driver {
396397 notify : Arc < Notify > ,
397398 waits : HashMap < usize , wait:: Wait > ,
398399 pool : AsyncifyPool ,
400+ completed_tx : Sender < Entry > ,
401+ completed_rx : Receiver < Entry > ,
399402 _local_marker : PhantomData < ErasedKey > ,
400403}
401404
@@ -407,8 +410,12 @@ impl Driver {
407410 let driver = port. as_raw_handle ( ) as _ ;
408411 let overlapped = Overlapped :: new ( driver) ;
409412 let notify = Arc :: new ( Notify :: new ( port, overlapped) ) ;
413+ let ( completed_tx, completed_rx) = flume:: unbounded ( ) ;
414+
410415 Ok ( Self {
411416 notify,
417+ completed_tx,
418+ completed_rx,
412419 waits : HashMap :: default ( ) ,
413420 pool : builder. create_or_get_thread_pool ( ) ,
414421 _local_marker : PhantomData ,
@@ -477,16 +484,14 @@ impl Driver {
477484 }
478485
479486 fn push_blocking ( & mut self , key : ErasedKey ) {
480- let notify = self . notify . clone ( ) ;
481487 // SAFETY: we're submitting into the driver, so it's safe to freeze here.
482488 let mut key = unsafe { key. freeze ( ) } ;
489+ let tx = self . completed_tx . clone ( ) ;
483490
484491 let mut closure = move || {
485- let op = key. as_mut ( ) ;
486- let res = op. operate_blocking ( ) ;
487- let optr = op. extra_mut ( ) . optr ( ) ;
488- // key will be unfronzen in `create_entry` when the result is ready
489- notify. port . post ( res, optr) . ok ( ) ;
492+ let res = key. as_mut ( ) . operate_blocking ( ) ;
493+ let entry = Entry :: new ( key. into_inner ( ) , res) ;
494+ _ = tx. send ( entry) ;
490495 } ;
491496
492497 while let Err ( e) = self . pool . dispatch ( closure) {
@@ -536,6 +541,10 @@ impl Driver {
536541
537542 let notify = & self . notify . overlapped as * const Overlapped ;
538543
544+ while let Ok ( entry) = self . completed_rx . try_recv ( ) {
545+ entry. notify ( ) ;
546+ }
547+
539548 for e in self . notify . port . poll ( timeout) ? {
540549 if let Some ( e) = Self :: create_entry ( notify, & mut self . waits , e) {
541550 e. notify ( )
0 commit comments