From 586f759c33f16d6c27b57c21b2e74696722a61c4 Mon Sep 17 00:00:00 2001 From: pln Date: Wed, 19 Apr 2017 22:31:23 +0200 Subject: [PATCH] mock updated mock_mut still broken --- src/lib.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b0a23b56e5..4fb110c8c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -147,6 +147,33 @@ impl Resource> { /// [Resource.borrow](struct.Resource.html#method.borrow). #[cfg(not(thumbv6m))] pub fn mock(&'static self, _prio: &C, _curr_ceil: &C, f: F) -> R + where + F: FnOnce(Ref, &C) -> R, + PRIOTASK: Unsigned, + CURRCEIL: Unsigned, + CEILING: GreaterThanOrEqual + Max + Level + Unsigned, + { + unsafe { + let c1 = ::to_u8(); + let c2 = ::to_u8(); + if c2 > c1 { + let old_basepri = basepri::read(); + basepri_max::write(::hw()); + barrier!(); + let ret = + f(Ref::new(&*self.data.get()), &C { _marker: PhantomData }); + barrier!(); + basepri::write(old_basepri); + ret + } else { + f(Ref::new(&*self.data.get()), &C { _marker: PhantomData }) + + } + } + } +/// Dummy documentation + #[cfg(not(thumbv6m))] + pub fn mock_mut(&'static self, _prio: &mut C, _curr_ceil: &mut C, f: F) -> R where F: FnOnce(Ref, C) -> R, PRIOTASK: Unsigned, @@ -161,7 +188,7 @@ impl Resource> { basepri_max::write(::hw()); barrier!(); let ret = - f(Ref::new(&*self.data.get()), C { _marker: PhantomData }); + f(Ref::new(&mut *self.data.get()), C { _marker: PhantomData }); barrier!(); basepri::write(old_basepri); ret @@ -172,7 +199,6 @@ impl Resource> { } } - /// Like [Resource.lock](struct.Resource.html#method.lock) but returns a /// `&mut-` reference ///