Skip to content

Commit

Permalink
remove unnecessary Option for mio::Events in `tokio::runtime::io:…
Browse files Browse the repository at this point in the history
…:Driver`
  • Loading branch information
byte-sourcerer committed Oct 6, 2022
1 parent 9b48635 commit d332eb4
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tokio/src/runtime/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) struct Driver {
tick: u8,

/// Reuse the `mio::Events` value across calls to poll.
events: Option<mio::Events>,
events: mio::Events,

/// Primary slab handle containing the state for each resource registered
/// with this driver.
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Driver {

Ok(Driver {
tick: 0,
events: Some(mio::Events::with_capacity(1024)),
events: mio::Events::with_capacity(1024),
poll,
resources: slab,
inner: Arc::new(Inner {
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Driver {
self.resources.compact()
}

let mut events = self.events.take().expect("i/o driver event store missing");
let mut events = &mut self.events;

// Block waiting for an event to happen, peeling out how many events
// happened.
Expand All @@ -194,27 +194,23 @@ impl Driver {
let token = event.token();

if token != TOKEN_WAKEUP {
self.dispatch(token, Ready::from_mio(event));
Self::dispatch(&mut self.resources, self.tick, token, Ready::from_mio(event));
ready_count += 1;
}
}

self.inner.metrics.incr_ready_count_by(ready_count);

self.events = Some(events);
}

fn dispatch(&mut self, token: mio::Token, ready: Ready) {
fn dispatch(resources: &mut Slab<ScheduledIo>, tick: u8, token: mio::Token, ready: Ready) {
let addr = slab::Address::from_usize(ADDRESS.unpack(token.0));

let resources = &mut self.resources;

let io = match resources.get(addr) {
Some(io) => io,
None => return,
};

let res = io.set_readiness(Some(token.0), Tick::Set(self.tick), |curr| curr | ready);
let res = io.set_readiness(Some(token.0), Tick::Set(tick), |curr| curr | ready);

if res.is_err() {
// token no longer valid!
Expand Down

0 comments on commit d332eb4

Please sign in to comment.