From 527bfb6eecf626b34996511689b80654ba0e26ed Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 13 Jun 2020 21:07:55 +0200 Subject: [PATCH] added compiler_fence(Ordering::SeqCst) around critical sections --- src/export.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/export.rs b/src/export.rs index e23b8f3a8b..4794f6988a 100644 --- a/src/export.rs +++ b/src/export.rs @@ -1,6 +1,6 @@ use core::{ cell::Cell, - sync::atomic::{AtomicBool, Ordering}, + sync::atomic::{compiler_fence, AtomicBool, Ordering}, }; pub use crate::tq::{NotReady, TimerQueue}; @@ -129,13 +129,20 @@ pub unsafe fn lock( if current < ceiling { if ceiling == (1 << nvic_prio_bits) { priority.set(u8::max_value()); - let r = interrupt::free(|_| f(&mut *ptr)); + let r = interrupt::free(|_| { + compiler_fence(Ordering::SeqCst); + let r = f(&mut *ptr); + compiler_fence(Ordering::SeqCst); + r + }); priority.set(current); r } else { priority.set(ceiling); basepri::write(logical2hw(ceiling, nvic_prio_bits)); + compiler_fence(Ordering::SeqCst); let r = f(&mut *ptr); + compiler_fence(Ordering::SeqCst); basepri::write(logical2hw(current, nvic_prio_bits)); priority.set(current); r @@ -158,7 +165,12 @@ pub unsafe fn lock( if current < ceiling { priority.set(u8::max_value()); - let r = interrupt::free(|_| f(&mut *ptr)); + let r = interrupt::free(|_| { + compiler_fence(Ordering::SeqCst); + let r = f(&mut *ptr); + compiler_fence(Ordering::SeqCst); + r + }); priority.set(current); r } else {