|
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}; |
4 | 2 |
|
5 |
| - use crate::interrupt; |
6 |
| - use crate::register::primask; |
| 3 | +use crate::interrupt; |
| 4 | +use crate::register::primask; |
7 | 5 |
|
8 |
| - struct SingleCoreCriticalSection; |
9 |
| - set_impl!(SingleCoreCriticalSection); |
| 6 | +struct SingleCoreCriticalSection; |
| 7 | +set_impl!(SingleCoreCriticalSection); |
10 | 8 |
|
11 |
| - unsafe impl Impl for SingleCoreCriticalSection { |
12 |
| - unsafe fn acquire() -> RawRestoreState { |
13 |
| - // Backup previous state of PRIMASK register. We access the entire register directly as a |
14 |
| - // u32 instead of using the primask::read() function to minimize the number of processor |
15 |
| - // cycles during which interrupts are disabled. |
16 |
| - let restore_state = primask::read_raw(); |
17 |
| - // NOTE: Fence guarantees are provided by interrupt::disable(), which performs a `compiler_fence(SeqCst)`. |
18 |
| - interrupt::disable(); |
19 |
| - restore_state |
20 |
| - } |
| 9 | +unsafe impl Impl for SingleCoreCriticalSection { |
| 10 | + unsafe fn acquire() -> RawRestoreState { |
| 11 | + // Backup previous state of PRIMASK register. We access the entire register directly as a |
| 12 | + // u32 instead of using the primask::read() function to minimize the number of processor |
| 13 | + // cycles during which interrupts are disabled. |
| 14 | + let restore_state = primask::read_raw(); |
| 15 | + // NOTE: Fence guarantees are provided by interrupt::disable(), which performs a `compiler_fence(SeqCst)`. |
| 16 | + interrupt::disable(); |
| 17 | + restore_state |
| 18 | + } |
21 | 19 |
|
22 |
| - unsafe fn release(restore_state: RawRestoreState) { |
23 |
| - // NOTE: Fence guarantees are provided by primask::write_raw(), which performs a `compiler_fence(SeqCst)`. |
24 |
| - primask::write_raw(restore_state); |
25 |
| - } |
| 20 | + unsafe fn release(restore_state: RawRestoreState) { |
| 21 | + // NOTE: Fence guarantees are provided by primask::write_raw(), which performs a `compiler_fence(SeqCst)`. |
| 22 | + primask::write_raw(restore_state); |
26 | 23 | }
|
27 | 24 | }
|
0 commit comments