Skip to content

Commit

Permalink
get rid of feature-gate macros
Browse files Browse the repository at this point in the history
  • Loading branch information
eagr committed Jan 17, 2024
1 parent 568c736 commit 73ccdb9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
71 changes: 33 additions & 38 deletions latches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,40 @@
//!
//! [`Barrier`]: std::sync::Barrier

/// The `sync` implementation is the default implementation of threads.
///
/// It depends on the `atomic-wait` feature by default, enable the `std`
/// feature will change this.
///
/// It support timeouts if the `std` feature is enabled.
#[cfg(feature = "sync")]
#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
pub mod sync;

/// The `futex` implementation.
///
/// It depends on the `atomic-wait` feature.
///
/// It does not support timeouts.
#[cfg(feature = "futex")]
#[cfg_attr(docsrs, doc(cfg(feature = "futex")))]
pub mod futex;

/// The `task` implementation.
///
/// Adding the `atomic-wait` feature or `std` feature make it more
/// concurrency-friendly for gate scenarios.
///
/// It supports timeouts, but this requires a timer. See also [`watch()`].
///
/// [`watch()`]: crate::task::Latch::watch
#[cfg(feature = "task")]
#[cfg_attr(docsrs, doc(cfg(feature = "task")))]
pub mod task;

mod macros;

macro_rules! cfg_item {
($feature:literal => $m:item) => {
#[cfg(feature = $feature)]
#[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
$m
};
($mt:meta => $($m:item)+) => {
$(
#[cfg($mt)]
Expand All @@ -41,39 +69,6 @@ macro_rules! cfg_item {
};
}

cfg_item! { "sync" =>
/// The `sync` implementation is the default implementation of threads.
///
/// It depends on the `atomic-wait` feature by default, enable the `std`
/// feature will change this.
///
/// It support timeouts if the `std` feature is enabled.
pub mod sync;
}

cfg_item! { "futex" =>
/// The `futex` implementation.
///
/// It depends on the `atomic-wait` feature.
///
/// It does not support timeouts.
pub mod futex;
}

cfg_item! { "task" =>
/// The `task` implementation.
///
/// Adding the `atomic-wait` feature or `std` feature make it more
/// concurrency-friendly for gate scenarios.
///
/// It supports timeouts, but this requires a timer. See also [`watch()`].
///
/// [`watch()`]: crate::task::Latch::watch
pub mod task;
}

mod macros;

cfg_item! { any(all(feature = "sync", feature = "std"), feature = "task") =>
pub use timeout::*;
mod timeout;
Expand Down
32 changes: 18 additions & 14 deletions latches/src/lock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
macro_rules! cfg_impl {
($f:meta => $m:ident $(,)?) => {
#[cfg(all(feature = "task", $f))]
pub(crate) use $m::Mutex;
#[cfg(all(feature = "task", feature = "std"))]
pub(crate) use stds::Mutex;
#[cfg(all(feature = "sync", feature = "std"))]
pub(crate) use stds::EmptyCondvar;
#[cfg(feature = "std")]
mod stds;

#[cfg(all(feature = "sync", $f))]
pub(crate) use $m::EmptyCondvar;
#[cfg(all(feature = "task", all(not(feature = "std"), feature = "atomic-wait")))]
pub(crate) use futexes::Mutex;
#[cfg(all(feature = "sync", all(not(feature = "std"), feature = "atomic-wait")))]
pub(crate) use futexes::EmptyCondvar;
#[cfg(all(not(feature = "std"), feature = "atomic-wait"))]
mod futexes;

#[cfg($f)]
mod $m;
};
}

cfg_impl!(feature = "std" => stds);
cfg_impl!(all(not(feature = "std"), feature = "atomic-wait") => futexes);
cfg_impl!(all(not(feature = "std"), not(feature = "atomic-wait")) => spins);
#[cfg(all(feature = "task", all(not(feature = "std"), not(feature = "atomic-wait"))))]
pub(crate) use spins::Mutex;
#[cfg(all(feature = "sync", all(not(feature = "std"), not(feature = "atomic-wait"))))]
pub(crate) use spins::EmptyCondvar;
#[cfg(all(not(feature = "std"), not(feature = "atomic-wait")))]
mod spins;

0 comments on commit 73ccdb9

Please sign in to comment.