Skip to content

Commit 462b550

Browse files
bors[bot]almindor
andauthored
Merge #117
117: fix atomicity of critical section, fixes #116 r=dkhayes117 a=almindor This changes `SingleHartCriticalSection::acquire` to be done in an atomic way. Fixes #116 NOTE: no changelog since it fixes a small bug on unreleased change Co-authored-by: Ales Katona <[email protected]>
2 parents d9c6076 + f847eba commit 462b550

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/critical_section.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ set_impl!(SingleHartCriticalSection);
88

99
unsafe impl Impl for SingleHartCriticalSection {
1010
unsafe fn acquire() -> RawRestoreState {
11-
let was_active = mstatus::read().mie();
12-
interrupt::disable();
13-
was_active
11+
let mut mstatus: usize;
12+
core::arch::asm!("csrrci {}, 0x300, 0b100", out(reg) mstatus);
13+
core::mem::transmute::<_, mstatus::Mstatus>(mstatus).mie()
1414
}
1515

1616
unsafe fn release(was_active: RawRestoreState) {

0 commit comments

Comments
 (0)