Przeglądaj źródła

fix atomicity of critical section, fixes #116

Ales Katona 2 lat temu
rodzic
commit
f847eba289
1 zmienionych plików z 3 dodań i 3 usunięć
  1. 3 3
      src/critical_section.rs

+ 3 - 3
src/critical_section.rs

@@ -8,9 +8,9 @@ set_impl!(SingleHartCriticalSection);
 
 unsafe impl Impl for SingleHartCriticalSection {
     unsafe fn acquire() -> RawRestoreState {
-        let was_active = mstatus::read().mie();
-        interrupt::disable();
-        was_active
+        let mut mstatus: usize;
+        core::arch::asm!("csrrci {}, 0x300, 0b100", out(reg) mstatus);
+        core::mem::transmute::<_, mstatus::Mstatus>(mstatus).mie()
     }
 
     unsafe fn release(was_active: RawRestoreState) {