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

metrics: fix compilation with unstable, process, and rt #4682

Merged
merged 1 commit into from May 11, 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
10 changes: 6 additions & 4 deletions tokio/src/io/driver/metrics.rs
Expand Up @@ -4,7 +4,7 @@
//! these need to be available in the case when `net` is enabled but
//! `rt` is not.

cfg_not_rt_and_metrics! {
cfg_not_rt_and_metrics_and_net! {
#[derive(Default)]
pub(crate) struct IoDriverMetrics {}

Expand All @@ -15,8 +15,10 @@ cfg_not_rt_and_metrics! {
}
}

cfg_rt! {
cfg_metrics! {
pub(crate) use crate::runtime::IoDriverMetrics;
cfg_net! {
cfg_rt! {
cfg_metrics! {
pub(crate) use crate::runtime::IoDriverMetrics;
}
}
}
28 changes: 15 additions & 13 deletions tokio/src/io/driver/mod.rs
Expand Up @@ -290,19 +290,21 @@ cfg_not_rt! {
}
}

cfg_metrics! {
impl Handle {
// TODO: Remove this when handle contains `Arc<Inner>` so that we can return
// &IoDriverMetrics instead of using a closure.
//
// Related issue: https://github.com/tokio-rs/tokio/issues/4509
pub(crate) fn with_io_driver_metrics<F, R>(&self, f: F) -> Option<R>
where
F: Fn(&IoDriverMetrics) -> R,
{
self.inner().map(|inner| f(&inner.metrics))
}
}
cfg_net! {
cfg_metrics! {
impl Handle {
// TODO: Remove this when handle contains `Arc<Inner>` so that we can return
// &IoDriverMetrics instead of using a closure.
//
// Related issue: https://github.com/tokio-rs/tokio/issues/4509
pub(crate) fn with_io_driver_metrics<F, R>(&self, f: F) -> Option<R>
where
F: Fn(&IoDriverMetrics) -> R,
{
self.inner().map(|inner| f(&inner.metrics))
}
}
}
}

impl Handle {
Expand Down
14 changes: 12 additions & 2 deletions tokio/src/macros/cfg.rs
Expand Up @@ -195,9 +195,19 @@ macro_rules! cfg_not_metrics {
}
}

macro_rules! cfg_not_rt_and_metrics {
macro_rules! cfg_not_rt_and_metrics_and_net {
($($item:item)*) => {
$( #[cfg(not(all(feature = "rt", all(tokio_unstable, not(loom)))))] $item )*
$( #[cfg(not(all(feature = "net", feature = "rt", all(tokio_unstable, not(loom)))))]$item )*
}
}

macro_rules! cfg_net_or_process {
($($item:item)*) => {
$(
#[cfg(any(feature = "net", feature = "process"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "net", feature = "process"))))]
$item
)*
}
}

Expand Down