Skip to content

Commit 25f1f95

Browse files
committed
Use a mod _export for macro reexports.
This avoids having to do `#[doc(hidden)] pub mod critical_section` which is a bit strange.
1 parent e0eeec4 commit 25f1f95

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/critical_section.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
#[cfg(all(cortex_m, feature = "critical-section-single-core"))]
2-
mod single_core_critical_section {
3-
use critical_section::{set_impl, Impl, RawRestoreState};
1+
use critical_section::{set_impl, Impl, RawRestoreState};
42

5-
use crate::interrupt;
6-
use crate::register::primask;
3+
use crate::interrupt;
4+
use crate::register::primask;
75

8-
struct SingleCoreCriticalSection;
9-
set_impl!(SingleCoreCriticalSection);
6+
struct SingleCoreCriticalSection;
7+
set_impl!(SingleCoreCriticalSection);
108

11-
unsafe impl Impl for SingleCoreCriticalSection {
12-
unsafe fn acquire() -> RawRestoreState {
13-
let was_active = primask::read().is_active();
14-
interrupt::disable();
15-
was_active
16-
}
9+
unsafe impl Impl for SingleCoreCriticalSection {
10+
unsafe fn acquire() -> RawRestoreState {
11+
let was_active = primask::read().is_active();
12+
interrupt::disable();
13+
was_active
14+
}
1715

18-
unsafe fn release(was_active: RawRestoreState) {
19-
// Only re-enable interrupts if they were enabled before the critical section.
20-
if was_active {
21-
interrupt::enable()
22-
}
16+
unsafe fn release(was_active: RawRestoreState) {
17+
// Only re-enable interrupts if they were enabled before the critical section.
18+
if was_active {
19+
interrupt::enable()
2320
}
2421
}
2522
}
26-
27-
pub use critical_section::with;

src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ mod macros;
4949
pub mod asm;
5050
#[cfg(armv8m)]
5151
pub mod cmse;
52-
// This is only public so the `singleton` macro does not require depending on
53-
// the `critical-section` crate separately.
54-
#[doc(hidden)]
55-
pub mod critical_section;
5652
pub mod delay;
5753
pub mod interrupt;
5854
#[cfg(all(not(armv6m), not(armv8m_base)))]
@@ -61,3 +57,13 @@ pub mod peripheral;
6157
pub mod register;
6258

6359
pub use crate::peripheral::Peripherals;
60+
61+
#[cfg(all(cortex_m, feature = "critical-section-single-core"))]
62+
mod critical_section;
63+
64+
/// Used to reexport items for use in macros. Do not use directly.
65+
/// Not covered by semver guarantees.
66+
#[doc(hidden)]
67+
pub mod _export {
68+
pub use critical_section;
69+
}

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ macro_rules! iprintln {
6565
#[macro_export]
6666
macro_rules! singleton {
6767
($name:ident: $ty:ty = $expr:expr) => {
68-
$crate::critical_section::with(|_| {
68+
$crate::_export::critical_section::with(|_| {
6969
// this is a tuple of a MaybeUninit and a bool because using an Option here is
7070
// problematic: Due to niche-optimization, an Option could end up producing a non-zero
7171
// initializer value which would move the entire static from `.bss` into `.data`...

0 commit comments

Comments
 (0)