1 | #[cfg (all(cortex_m, feature = "critical-section-single-core" ))] |
2 | mod single_core_critical_section { |
3 | use critical_section::{set_impl, Impl, RawRestoreState}; |
4 | |
5 | use crate::interrupt; |
6 | use crate::register::primask; |
7 | |
8 | struct SingleCoreCriticalSection; |
9 | set_impl!(SingleCoreCriticalSection); |
10 | |
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 | } |
17 | |
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 | } |
23 | } |
24 | } |
25 | } |
26 | |