Skip to content

Commit

Permalink
add compiler barriers to interrupt::free
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Jun 30, 2017
1 parent cb7a60a commit 93c901d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub struct CriticalSection {
_0: (),
}

macro_rules! barrier {
() => { asm!("" ::: "memory" : "volatile") }
}

/// Execute closure `f` in an interrupt-free context.
///
/// This as also known as a "critical section".
Expand All @@ -93,7 +97,9 @@ where
// disable interrupts
disable();

unsafe { barrier!() }
let r = f(&CriticalSection { _0: () });
unsafe { barrier!() }

// If the interrupts were active before our `disable` call, then re-enable
// them. Otherwise, keep them disabled
Expand Down

0 comments on commit 93c901d

Please sign in to comment.