blob: e3d57d19d173e76c22d0b7f8858688133bec1ce6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use critical_section::{set_impl, Impl, RawRestoreState};
use crate::interrupt;
use crate::register::primask;
struct SingleCoreCriticalSection;
set_impl!(SingleCoreCriticalSection);
unsafe impl Impl for SingleCoreCriticalSection {
unsafe fn acquire() -> RawRestoreState {
let was_active = primask::read().is_active();
interrupt::disable();
was_active
}
unsafe fn release(was_active: RawRestoreState) {
// Only re-enable interrupts if they were enabled before the critical section.
if was_active {
interrupt::enable()
}
}
}
|