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 signal driver to runtime module #5121

Merged
merged 2 commits into from Oct 24, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions tokio/src/macros/cfg.rs
Expand Up @@ -297,6 +297,13 @@ macro_rules! cfg_signal_internal {
}
}

macro_rules! cfg_signal_internal_and_unix {
($($item:item)*) => {
#[cfg(unix)]
cfg_signal_internal! { $($item)* }
}
}

macro_rules! cfg_not_signal_internal {
($($item:item)*) => {
$(
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/process/unix/driver.rs
Expand Up @@ -3,7 +3,7 @@
//! Process driver.

use crate::process::unix::GlobalOrphanQueue;
use crate::signal::unix::driver::{Driver as SignalDriver, Handle as SignalHandle};
use crate::runtime::signal::{Driver as SignalDriver, Handle as SignalHandle};

use std::time::Duration;

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/process/unix/mod.rs
Expand Up @@ -32,7 +32,7 @@ use reap::Reaper;
use crate::io::{AsyncRead, AsyncWrite, PollEvented, ReadBuf};
use crate::process::kill::Kill;
use crate::process::SpawnedChild;
use crate::signal::unix::driver::Handle as SignalHandle;
use crate::runtime::signal::Handle as SignalHandle;
use crate::signal::unix::{signal, Signal, SignalKind};

use mio::event::Source;
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/process/unix/orphan.rs
@@ -1,5 +1,5 @@
use crate::loom::sync::{Mutex, MutexGuard};
use crate::signal::unix::driver::Handle as SignalHandle;
use crate::runtime::signal::Handle as SignalHandle;
use crate::signal::unix::{signal_with_handle, SignalKind};
use crate::sync::watch;
use std::io;
Expand Down Expand Up @@ -132,7 +132,7 @@ where
pub(crate) mod test {
use super::*;
use crate::runtime::io::Driver as IoDriver;
use crate::signal::unix::driver::{Driver as SignalDriver, Handle as SignalHandle};
use crate::runtime::signal::{Driver as SignalDriver, Handle as SignalHandle};
use crate::sync::watch;
use std::cell::{Cell, RefCell};
use std::io;
Expand Down
13 changes: 3 additions & 10 deletions tokio/src/runtime/driver.rs
Expand Up @@ -211,19 +211,12 @@ cfg_not_io_driver! {

// ===== signal driver =====

macro_rules! cfg_signal_internal_and_unix {
($($item:item)*) => {
#[cfg(unix)]
cfg_signal_internal! { $($item)* }
}
}

cfg_signal_internal_and_unix! {
type SignalDriver = crate::signal::unix::driver::Driver;
pub(crate) type SignalHandle = Option<crate::signal::unix::driver::Handle>;
type SignalDriver = crate::runtime::signal::Driver;
pub(crate) type SignalHandle = Option<crate::runtime::signal::Handle>;

fn create_signal_driver(io_driver: IoDriver) -> io::Result<(SignalDriver, SignalHandle)> {
let driver = crate::signal::unix::driver::Driver::new(io_driver)?;
let driver = crate::runtime::signal::Driver::new(io_driver)?;
let handle = driver.handle();
Ok((driver, Some(handle)))
}
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/runtime/mod.rs
Expand Up @@ -188,6 +188,10 @@ cfg_time! {
pub(crate) mod time;
}

cfg_signal_internal_and_unix! {
pub(crate) mod signal;
}

cfg_rt! {
pub(crate) mod enter;

Expand Down
Expand Up @@ -150,7 +150,7 @@ unsafe fn noop(_data: *const ()) {}
// ===== impl Handle =====

impl Handle {
pub(super) fn check_inner(&self) -> std_io::Result<()> {
pub(crate) fn check_inner(&self) -> std_io::Result<()> {
if self.inner.strong_count() > 0 {
Ok(())
} else {
Expand All @@ -170,7 +170,7 @@ cfg_rt! {
///
/// This function panics if there is no current signal driver set.
#[track_caller]
pub(super) fn current() -> Self {
pub(crate) fn current() -> Self {
crate::runtime::context::signal_handle().expect(
"there is no signal driver running, must be called from the context of Tokio runtime",
)
Expand All @@ -186,7 +186,7 @@ cfg_not_rt! {
///
/// This function panics if there is no current signal driver set.
#[track_caller]
pub(super) fn current() -> Self {
pub(crate) fn current() -> Self {
panic!(
"there is no signal driver running, must be called from the context of Tokio runtime or with\
`rt` enabled.",
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/signal/mod.rs
Expand Up @@ -48,7 +48,7 @@ use std::task::{Context, Poll};
mod ctrl_c;
pub use ctrl_c::ctrl_c;

mod registry;
pub(crate) mod registry;

mod os {
#[cfg(unix)]
Expand Down
6 changes: 2 additions & 4 deletions tokio/src/signal/unix.rs
Expand Up @@ -6,6 +6,7 @@
#![cfg(unix)]
#![cfg_attr(docsrs, doc(cfg(all(unix, feature = "signal"))))]

use crate::runtime::signal::Handle;
use crate::signal::registry::{globals, EventId, EventInfo, Globals, Init, Storage};
use crate::signal::RxFuture;
use crate::sync::watch;
Expand All @@ -17,9 +18,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;
use std::task::{Context, Poll};

pub(crate) mod driver;
use self::driver::Handle;

pub(crate) type OsStorage = Vec<SignalInfo>;

impl Init for OsStorage {
Expand Down Expand Up @@ -52,7 +50,7 @@ impl Storage for OsStorage {
#[derive(Debug)]
pub(crate) struct OsExtraData {
sender: UnixStream,
receiver: UnixStream,
pub(crate) receiver: UnixStream,
}

impl Init for OsExtraData {
Expand Down