diff --git a/latches/src/lib.rs b/latches/src/lib.rs index 26af905..9188b42 100644 --- a/latches/src/lib.rs +++ b/latches/src/lib.rs @@ -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)] @@ -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; diff --git a/latches/src/lock/mod.rs b/latches/src/lock/mod.rs index 325db3a..ff3a799 100644 --- a/latches/src/lock/mod.rs +++ b/latches/src/lock/mod.rs @@ -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;