Skip to content

Commit

Permalink
rt: move signal driver to runtime module (#5121)
Browse files Browse the repository at this point in the history
The signal feature only requires a driver with unix platforms. The
unix signal driver uses the I/O driver. A future refactor would like to
make the signal driver use internal APIs of the I/O driver. To do this,
the signal driver must be moved to the runtime module.
  • Loading branch information
carllerche authored Oct 24, 2022
1 parent 80568df commit 1ca17be
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
7 changes: 7 additions & 0 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 1ca17be

Please sign in to comment.