From f2bab47aa4bdd04f79e608debe64e3ddcea07702 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 7 Apr 2017 18:14:48 -0500 Subject: allow returns from checked::Resource.lock{,mut} also add compiler barriers --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 95aa8ba..7cd0ff6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,9 @@ where lock_check(ceiling); let old_basepri = basepri::read(); basepri_max::write(ceiling); + compiler_barrier(); let ret = f(&*res, ptr::read(0 as *const _)); + compiler_barrier(); basepri::write(old_basepri); ret } @@ -121,11 +123,23 @@ where lock_check(ceiling); let old_basepri = basepri::read(); basepri_max::write(ceiling); + compiler_barrier(); let ret = f(&mut *res, ptr::read(0 as *const _)); + compiler_barrier(); basepri::write(old_basepri); ret } +fn compiler_barrier() { + unsafe { + asm!("" + : + : + : "memory" + : "volatile"); + } +} + /// A peripheral as a resource pub struct ResourceP where -- cgit v1.2.3