Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary Option for mio::Events in Driver #5078

Merged
merged 1 commit into from Oct 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions tokio/src/runtime/io/mod.rs
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,28 @@ 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