diff options
Diffstat (limited to 'tokio/src/signal')
-rw-r--r-- | tokio/src/signal/registry.rs | 2 | ||||
-rw-r--r-- | tokio/src/signal/unix/driver.rs | 45 | ||||
-rw-r--r-- | tokio/src/signal/windows.rs | 3 |
3 files changed, 35 insertions, 15 deletions
diff --git a/tokio/src/signal/registry.rs b/tokio/src/signal/registry.rs index 9e55a5e6..5d6f608c 100644 --- a/tokio/src/signal/registry.rs +++ b/tokio/src/signal/registry.rs @@ -306,7 +306,7 @@ mod tests { } fn rt() -> Runtime { - runtime::Builder::new().basic_scheduler().build().unwrap() + runtime::Builder::new_current_thread().build().unwrap() } async fn collect(mut rx: crate::sync::mpsc::Receiver<()>) -> Vec<()> { diff --git a/tokio/src/signal/unix/driver.rs b/tokio/src/signal/unix/driver.rs index d0615312..d4a49783 100644 --- a/tokio/src/signal/unix/driver.rs +++ b/tokio/src/signal/unix/driver.rs @@ -1,9 +1,10 @@ +#![cfg_attr(not(feature = "rt-core"), allow(dead_code))] + //! Signal driver use crate::io::driver::Driver as IoDriver; use crate::io::PollEvented; use crate::park::Park; -use crate::runtime::context; use crate::signal::registry::globals; use mio::net::UnixStream; @@ -165,17 +166,6 @@ impl Park for Driver { // ===== impl Handle ===== impl Handle { - /// Returns a handle to the current driver - /// - /// # Panics - /// - /// This function panics if there is no current signal driver set. - pub(super) fn current() -> Self { - context::signal_handle().expect( - "there is no signal driver running, must be called from the context of Tokio runtime", - ) - } - pub(super) fn check_inner(&self) -> io::Result<()> { if self.inner.strong_count() > 0 { Ok(()) @@ -184,3 +174,34 @@ impl Handle { } } } + +cfg_rt_core! { + impl Handle { + /// Returns a handle to the current driver + /// + /// # Panics + /// + /// This function panics if there is no current signal driver set. + pub(super) fn current() -> Self { + crate::runtime::context::signal_handle().expect( + "there is no signal driver running, must be called from the context of Tokio runtime", + ) + } + } +} + +cfg_not_rt_core! { + impl Handle { + /// Returns a handle to the current driver + /// + /// # Panics + /// + /// This function panics if there is no current signal driver set. + pub(super) fn current() -> Self { + panic!( + "there is no signal driver running, must be called from the context of Tokio runtime or with\ + `rt-core` enabled.", + ) + } + } +} diff --git a/tokio/src/signal/windows.rs b/tokio/src/signal/windows.rs index f638eed8..46271722 100644 --- a/tokio/src/signal/windows.rs +++ b/tokio/src/signal/windows.rs @@ -289,8 +289,7 @@ mod tests { } fn rt() -> Runtime { - crate::runtime::Builder::new() - .basic_scheduler() + crate::runtime::Builder::new_current_thread() .build() .unwrap() } |