Skip to content

Commit f65d6bf

Browse files
eagrmirromutth
authored andcommitted
get rid of feature-gate macros
1 parent 568c736 commit f65d6bf

File tree

2 files changed

+51
-52
lines changed

2 files changed

+51
-52
lines changed

latches/src/lib.rs

+33-38
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,40 @@
2626
//!
2727
//! [`Barrier`]: std::sync::Barrier
2828
29+
/// The `sync` implementation is the default implementation of threads.
30+
///
31+
/// It depends on the `atomic-wait` feature by default, enable the `std`
32+
/// feature will change this.
33+
///
34+
/// It support timeouts if the `std` feature is enabled.
35+
#[cfg(feature = "sync")]
36+
#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
37+
pub mod sync;
38+
39+
/// The `futex` implementation.
40+
///
41+
/// It depends on the `atomic-wait` feature.
42+
///
43+
/// It does not support timeouts.
44+
#[cfg(feature = "futex")]
45+
#[cfg_attr(docsrs, doc(cfg(feature = "futex")))]
46+
pub mod futex;
47+
48+
/// The `task` implementation.
49+
///
50+
/// Adding the `atomic-wait` feature or `std` feature make it more
51+
/// concurrency-friendly for gate scenarios.
52+
///
53+
/// It supports timeouts, but this requires a timer. See also [`watch()`].
54+
///
55+
/// [`watch()`]: crate::task::Latch::watch
56+
#[cfg(feature = "task")]
57+
#[cfg_attr(docsrs, doc(cfg(feature = "task")))]
58+
pub mod task;
59+
60+
mod macros;
61+
2962
macro_rules! cfg_item {
30-
($feature:literal => $m:item) => {
31-
#[cfg(feature = $feature)]
32-
#[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
33-
$m
34-
};
3563
($mt:meta => $($m:item)+) => {
3664
$(
3765
#[cfg($mt)]
@@ -41,39 +69,6 @@ macro_rules! cfg_item {
4169
};
4270
}
4371

44-
cfg_item! { "sync" =>
45-
/// The `sync` implementation is the default implementation of threads.
46-
///
47-
/// It depends on the `atomic-wait` feature by default, enable the `std`
48-
/// feature will change this.
49-
///
50-
/// It support timeouts if the `std` feature is enabled.
51-
pub mod sync;
52-
}
53-
54-
cfg_item! { "futex" =>
55-
/// The `futex` implementation.
56-
///
57-
/// It depends on the `atomic-wait` feature.
58-
///
59-
/// It does not support timeouts.
60-
pub mod futex;
61-
}
62-
63-
cfg_item! { "task" =>
64-
/// The `task` implementation.
65-
///
66-
/// Adding the `atomic-wait` feature or `std` feature make it more
67-
/// concurrency-friendly for gate scenarios.
68-
///
69-
/// It supports timeouts, but this requires a timer. See also [`watch()`].
70-
///
71-
/// [`watch()`]: crate::task::Latch::watch
72-
pub mod task;
73-
}
74-
75-
mod macros;
76-
7772
cfg_item! { any(all(feature = "sync", feature = "std"), feature = "task") =>
7873
pub use timeout::*;
7974
mod timeout;

latches/src/lock/mod.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
macro_rules! cfg_impl {
2-
($f:meta => $m:ident $(,)?) => {
3-
#[cfg(all(feature = "task", $f))]
4-
pub(crate) use $m::Mutex;
1+
#[cfg(all(feature = "task", feature = "std"))]
2+
pub(crate) use stds::Mutex;
3+
#[cfg(all(feature = "sync", feature = "std"))]
4+
pub(crate) use stds::EmptyCondvar;
5+
#[cfg(feature = "std")]
6+
mod stds;
57

6-
#[cfg(all(feature = "sync", $f))]
7-
pub(crate) use $m::EmptyCondvar;
8+
#[cfg(all(feature = "task", all(not(feature = "std"), feature = "atomic-wait")))]
9+
pub(crate) use futexes::Mutex;
10+
#[cfg(all(feature = "sync", all(not(feature = "std"), feature = "atomic-wait")))]
11+
pub(crate) use futexes::EmptyCondvar;
12+
#[cfg(all(not(feature = "std"), feature = "atomic-wait"))]
13+
mod futexes;
814

9-
#[cfg($f)]
10-
mod $m;
11-
};
12-
}
13-
14-
cfg_impl!(feature = "std" => stds);
15-
cfg_impl!(all(not(feature = "std"), feature = "atomic-wait") => futexes);
16-
cfg_impl!(all(not(feature = "std"), not(feature = "atomic-wait")) => spins);
15+
#[cfg(all(feature = "task", all(not(feature = "std"), not(feature = "atomic-wait"))))]
16+
pub(crate) use spins::Mutex;
17+
#[cfg(all(feature = "sync", all(not(feature = "std"), not(feature = "atomic-wait"))))]
18+
pub(crate) use spins::EmptyCondvar;
19+
#[cfg(all(not(feature = "std"), not(feature = "atomic-wait")))]
20+
mod spins;

0 commit comments

Comments
 (0)