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

rt: move I/O driver into runtime module #4942

Merged
merged 4 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion tokio/src/io/async_fd.rs
@@ -1,4 +1,5 @@
use crate::io::driver::{Handle, Interest, ReadyEvent, Registration};
use crate::io::Interest;
use crate::runtime::io::{Handle, ReadyEvent, Registration};

use mio::unix::SourceFd;
use std::io;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/bsd/poll_aio.rs
@@ -1,6 +1,6 @@
//! Use POSIX AIO futures with Tokio.

use crate::io::driver::{Handle, Interest, ReadyEvent, Registration};
use crate::runtime::io::{Handle, Interest, ReadyEvent, Registration};
use mio::event::Source;
use mio::Registry;
use mio::Token;
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/driver/interest.rs → tokio/src/io/interest.rs
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "net"), allow(dead_code, unreachable_pub))]

use crate::io::driver::Ready;
use crate::io::ready::Ready;

use std::fmt;
use std::ops;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Interest {
self.0
}

pub(super) fn mask(self) -> Ready {
pub(crate) fn mask(self) -> Ready {
match self {
Interest::READABLE => Ready::READABLE | Ready::READ_CLOSED,
Interest::WRITABLE => Ready::WRITABLE | Ready::WRITE_CLOSED,
Expand Down
6 changes: 4 additions & 2 deletions tokio/src/io/mod.rs
Expand Up @@ -205,10 +205,12 @@ pub use self::read_buf::ReadBuf;
pub use std::io::{Error, ErrorKind, Result, SeekFrom};

cfg_io_driver_impl! {
pub(crate) mod driver;
pub(crate) mod interest;
pub(crate) mod ready;

cfg_net! {
pub use driver::{Interest, Ready};
pub use interest::Interest;
pub use ready::Ready;
}

#[cfg_attr(tokio_wasi, allow(unused_imports))]
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/io/poll_evented.rs
@@ -1,4 +1,5 @@
use crate::io::driver::{Handle, Interest, Registration};
use crate::io::interest::Interest;
use crate::runtime::io::{Handle, Registration};

use mio::event::Source;
use std::fmt;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tokio/src/process/unix/orphan.rs
Expand Up @@ -120,7 +120,7 @@ where
#[cfg(all(test, not(loom)))]
pub(crate) mod test {
use super::*;
use crate::io::driver::Driver as IoDriver;
use crate::runtime::io::Driver as IoDriver;
use crate::signal::unix::driver::{Driver as SignalDriver, Handle as SignalHandle};
use crate::sync::watch;
use std::cell::{Cell, RefCell};
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/driver.rs
Expand Up @@ -8,9 +8,9 @@ use std::time::Duration;
// ===== io driver =====

cfg_io_driver! {
type IoDriver = crate::io::driver::Driver;
type IoDriver = crate::runtime::io::Driver;
type IoStack = crate::park::either::Either<ProcessDriver, ParkThread>;
pub(crate) type IoHandle = Option<crate::io::driver::Handle>;
pub(crate) type IoHandle = Option<crate::runtime::io::Handle>;

fn create_io_stack(enabled: bool) -> io::Result<(IoStack, IoHandle, SignalHandle)> {
use crate::park::either::Either;
Expand All @@ -19,7 +19,7 @@ cfg_io_driver! {
assert!(!enabled);

let ret = if enabled {
let io_driver = crate::io::driver::Driver::new()?;
let io_driver = crate::runtime::io::Driver::new()?;
let io_handle = io_driver.handle();

let (signal_driver, signal_handle) = create_signal_driver(io_driver)?;
Expand Down
File renamed without changes.
14 changes: 4 additions & 10 deletions tokio/src/io/driver/mod.rs → tokio/src/runtime/io/mod.rs
@@ -1,13 +1,5 @@
#![cfg_attr(not(feature = "rt"), allow(dead_code))]

mod interest;
#[allow(unreachable_pub)]
pub use interest::Interest;

mod ready;
#[allow(unreachable_pub)]
pub use ready::Ready;

mod registration;
pub(crate) use registration::Registration;

Expand All @@ -16,6 +8,8 @@ use scheduled_io::ScheduledIo;

mod metrics;

use crate::io::interest::Interest;
use crate::io::ready::Ready;
use crate::park::{Park, Unpark};
use crate::util::slab::{self, Slab};
use crate::{loom::sync::RwLock, util::bit};
Expand Down Expand Up @@ -268,7 +262,7 @@ cfg_rt! {
/// This function panics if there is no current reactor set and `rt` feature
/// flag is not enabled.
#[track_caller]
pub(super) fn current() -> Self {
pub(crate) fn current() -> Self {
crate::runtime::context::io_handle().expect("A Tokio 1.x context was found, but IO is disabled. Call `enable_io` on the runtime builder to enable IO.")
}
}
Expand All @@ -283,7 +277,7 @@ cfg_not_rt! {
/// This function panics if there is no current reactor set, or if the `rt`
/// feature flag is not enabled.
#[track_caller]
pub(super) fn current() -> Self {
pub(crate) fn current() -> Self {
panic!("{}", crate::util::error::CONTEXT_MISSING_ERROR)
}
}
Expand Down
File renamed without changes.
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "net"), allow(dead_code))]

use crate::io::driver::{Direction, Handle, Interest, ReadyEvent, ScheduledIo};
use crate::io::interest::Interest;
use crate::runtime::io::{Direction, Handle, ReadyEvent, ScheduledIo};
use crate::util::slab;

use mio::event::Source;
Expand Down
@@ -1,4 +1,6 @@
use super::{Interest, Ready, ReadyEvent, Tick};
use super::{ReadyEvent, Tick};
use crate::io::interest::Interest;
use crate::io::ready::Ready;
use crate::loom::sync::atomic::AtomicUsize;
use crate::loom::sync::Mutex;
use crate::util::bit;
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/runtime/mod.rs
Expand Up @@ -182,6 +182,10 @@ pub(crate) mod enter;

pub(crate) mod task;

cfg_io_driver_impl! {
pub(crate) mod io;
}

cfg_metrics! {
mod metrics;
pub use metrics::RuntimeMetrics;
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/signal/unix/driver.rs
Expand Up @@ -2,9 +2,10 @@

//! Signal driver

use crate::io::driver::{Driver as IoDriver, Interest};
use crate::io::PollEvented;
use crate::io::interest::Interest;
use crate::park::Park;
use crate::runtime::io::Driver as IoDriver;
use crate::signal::registry::globals;

use mio::net::UnixStream;
Expand Down