@@ -15,7 +15,7 @@ use std::time::{Duration, Instant};
15
15
use async_lock:: OnceCell ;
16
16
use concurrent_queue:: ConcurrentQueue ;
17
17
use futures_lite:: ready;
18
- use polling:: { Event , Poller } ;
18
+ use polling:: { Event , Events , Poller } ;
19
19
use slab:: Slab ;
20
20
21
21
// Choose the proper implementation of `Registration` based on the target platform.
@@ -77,7 +77,7 @@ pub(crate) struct Reactor {
77
77
/// Temporary storage for I/O events when polling the reactor.
78
78
///
79
79
/// Holding a lock on this event list implies the exclusive right to poll I/O.
80
- events : Mutex < Vec < Event > > ,
80
+ events : Mutex < Events > ,
81
81
82
82
/// An ordered map of registered timers.
83
83
///
@@ -104,7 +104,7 @@ impl Reactor {
104
104
poller : Poller :: new ( ) . expect ( "cannot initialize I/O event notification" ) ,
105
105
ticker : AtomicUsize :: new ( 0 ) ,
106
106
sources : Mutex :: new ( Slab :: new ( ) ) ,
107
- events : Mutex :: new ( Vec :: new ( ) ) ,
107
+ events : Mutex :: new ( Events :: new ( ) ) ,
108
108
timers : Mutex :: new ( BTreeMap :: new ( ) ) ,
109
109
timer_ops : ConcurrentQueue :: bounded ( TIMER_QUEUE_SIZE ) ,
110
110
}
@@ -268,7 +268,7 @@ impl Reactor {
268
268
/// A lock on the reactor.
269
269
pub ( crate ) struct ReactorLock < ' a > {
270
270
reactor : & ' a Reactor ,
271
- events : MutexGuard < ' a , Vec < Event > > ,
271
+ events : MutexGuard < ' a , Events > ,
272
272
}
273
273
274
274
impl ReactorLock < ' _ > {
@@ -331,14 +331,16 @@ impl ReactorLock<'_> {
331
331
// e.g. we were previously interested in both readability and writability,
332
332
// but only one of them was emitted.
333
333
if !state[ READ ] . is_empty ( ) || !state[ WRITE ] . is_empty ( ) {
334
- source. registration . modify (
335
- & self . reactor . poller ,
336
- Event {
337
- key : source. key ,
338
- readable : !state[ READ ] . is_empty ( ) ,
339
- writable : !state[ WRITE ] . is_empty ( ) ,
340
- } ,
341
- ) ?;
334
+ // Create the event that we are interested in.
335
+ let event = {
336
+ let mut event = Event :: none ( source. key ) ;
337
+ event. readable = !state[ READ ] . is_empty ( ) ;
338
+ event. writable = !state[ WRITE ] . is_empty ( ) ;
339
+ event
340
+ } ;
341
+
342
+ // Register interest in this event.
343
+ source. registration . modify ( & self . reactor . poller , event) ?;
342
344
}
343
345
}
344
346
}
@@ -463,14 +465,16 @@ impl Source {
463
465
464
466
// Update interest in this I/O handle.
465
467
if was_empty {
466
- self . registration . modify (
467
- & Reactor :: get ( ) . poller ,
468
- Event {
469
- key : self . key ,
470
- readable : !state[ READ ] . is_empty ( ) ,
471
- writable : !state[ WRITE ] . is_empty ( ) ,
472
- } ,
473
- ) ?;
468
+ // Create the event that we are interested in.
469
+ let event = {
470
+ let mut event = Event :: none ( self . key ) ;
471
+ event. readable = !state[ READ ] . is_empty ( ) ;
472
+ event. writable = !state[ WRITE ] . is_empty ( ) ;
473
+ event
474
+ } ;
475
+
476
+ // Register interest in it.
477
+ self . registration . modify ( & Reactor :: get ( ) . poller , event) ?;
474
478
}
475
479
476
480
Poll :: Pending
@@ -637,14 +641,20 @@ impl<H: Borrow<crate::Async<T>> + Clone, T> Future for Ready<H, T> {
637
641
638
642
// Update interest in this I/O handle.
639
643
if was_empty {
640
- handle. borrow ( ) . source . registration . modify (
641
- & Reactor :: get ( ) . poller ,
642
- Event {
643
- key : handle. borrow ( ) . source . key ,
644
- readable : !state[ READ ] . is_empty ( ) ,
645
- writable : !state[ WRITE ] . is_empty ( ) ,
646
- } ,
647
- ) ?;
644
+ // Create the event that we are interested in.
645
+ let event = {
646
+ let mut event = Event :: none ( handle. borrow ( ) . source . key ) ;
647
+ event. readable = !state[ READ ] . is_empty ( ) ;
648
+ event. writable = !state[ WRITE ] . is_empty ( ) ;
649
+ event
650
+ } ;
651
+
652
+ // Indicate that we are interested in this event.
653
+ handle
654
+ . borrow ( )
655
+ . source
656
+ . registration
657
+ . modify ( & Reactor :: get ( ) . poller , event) ?;
648
658
}
649
659
650
660
Poll :: Pending
0 commit comments