瀏覽代碼

fix atomicity of critical section, fixes #116

Ales Katona 2 年之前
父節點
當前提交
f847eba289
共有 1 個文件被更改,包括 3 次插入3 次删除
  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) {