rt: move signal driver to runtime module (#5121)

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.
This commit is contained in:
Carl Lerche 2022-10-24 15:51:18 -07:00 committed by GitHub
parent 80568dfc6d
commit 1ca17bef67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 22 deletions

View File

@ -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 { macro_rules! cfg_not_signal_internal {
($($item:item)*) => { ($($item:item)*) => {
$( $(

View File

@ -3,7 +3,7 @@
//! Process driver. //! Process driver.
use crate::process::unix::GlobalOrphanQueue; 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; use std::time::Duration;

View File

@ -32,7 +32,7 @@ use reap::Reaper;
use crate::io::{AsyncRead, AsyncWrite, PollEvented, ReadBuf}; use crate::io::{AsyncRead, AsyncWrite, PollEvented, ReadBuf};
use crate::process::kill::Kill; use crate::process::kill::Kill;
use crate::process::SpawnedChild; 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 crate::signal::unix::{signal, Signal, SignalKind};
use mio::event::Source; use mio::event::Source;

View File

@ -1,5 +1,5 @@
use crate::loom::sync::{Mutex, MutexGuard}; 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::signal::unix::{signal_with_handle, SignalKind};
use crate::sync::watch; use crate::sync::watch;
use std::io; use std::io;
@ -132,7 +132,7 @@ where
pub(crate) mod test { pub(crate) mod test {
use super::*; use super::*;
use crate::runtime::io::Driver as IoDriver; 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 crate::sync::watch;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::io; use std::io;

View File

@ -211,19 +211,12 @@ cfg_not_io_driver! {
// ===== signal driver ===== // ===== signal driver =====
macro_rules! cfg_signal_internal_and_unix {
($($item:item)*) => {
#[cfg(unix)]
cfg_signal_internal! { $($item)* }
}
}
cfg_signal_internal_and_unix! { cfg_signal_internal_and_unix! {
type SignalDriver = crate::signal::unix::driver::Driver; type SignalDriver = crate::runtime::signal::Driver;
pub(crate) type SignalHandle = Option<crate::signal::unix::driver::Handle>; pub(crate) type SignalHandle = Option<crate::runtime::signal::Handle>;
fn create_signal_driver(io_driver: IoDriver) -> io::Result<(SignalDriver, SignalHandle)> { 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(); let handle = driver.handle();
Ok((driver, Some(handle))) Ok((driver, Some(handle)))
} }

View File

@ -188,6 +188,10 @@ cfg_time! {
pub(crate) mod time; pub(crate) mod time;
} }
cfg_signal_internal_and_unix! {
pub(crate) mod signal;
}
cfg_rt! { cfg_rt! {
pub(crate) mod enter; pub(crate) mod enter;

View File

@ -150,7 +150,7 @@ unsafe fn noop(_data: *const ()) {}
// ===== impl Handle ===== // ===== impl Handle =====
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 { if self.inner.strong_count() > 0 {
Ok(()) Ok(())
} else { } else {
@ -170,7 +170,7 @@ cfg_rt! {
/// ///
/// This function panics if there is no current signal driver set. /// This function panics if there is no current signal driver set.
#[track_caller] #[track_caller]
pub(super) fn current() -> Self { pub(crate) fn current() -> Self {
crate::runtime::context::signal_handle().expect( crate::runtime::context::signal_handle().expect(
"there is no signal driver running, must be called from the context of Tokio runtime", "there is no signal driver running, must be called from the context of Tokio runtime",
) )
@ -186,7 +186,7 @@ cfg_not_rt! {
/// ///
/// This function panics if there is no current signal driver set. /// This function panics if there is no current signal driver set.
#[track_caller] #[track_caller]
pub(super) fn current() -> Self { pub(crate) fn current() -> Self {
panic!( panic!(
"there is no signal driver running, must be called from the context of Tokio runtime or with\ "there is no signal driver running, must be called from the context of Tokio runtime or with\
`rt` enabled.", `rt` enabled.",

View File

@ -48,7 +48,7 @@ use std::task::{Context, Poll};
mod ctrl_c; mod ctrl_c;
pub use ctrl_c::ctrl_c; pub use ctrl_c::ctrl_c;
mod registry; pub(crate) mod registry;
mod os { mod os {
#[cfg(unix)] #[cfg(unix)]

View File

@ -6,6 +6,7 @@
#![cfg(unix)] #![cfg(unix)]
#![cfg_attr(docsrs, doc(cfg(all(unix, feature = "signal"))))] #![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::registry::{globals, EventId, EventInfo, Globals, Init, Storage};
use crate::signal::RxFuture; use crate::signal::RxFuture;
use crate::sync::watch; use crate::sync::watch;
@ -17,9 +18,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once; use std::sync::Once;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
pub(crate) mod driver;
use self::driver::Handle;
pub(crate) type OsStorage = Vec<SignalInfo>; pub(crate) type OsStorage = Vec<SignalInfo>;
impl Init for OsStorage { impl Init for OsStorage {
@ -52,7 +50,7 @@ impl Storage for OsStorage {
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct OsExtraData { pub(crate) struct OsExtraData {
sender: UnixStream, sender: UnixStream,
receiver: UnixStream, pub(crate) receiver: UnixStream,
} }
impl Init for OsExtraData { impl Init for OsExtraData {