diff options
author | 2017-03-11 19:41:24 -0500 | |
---|---|---|
committer | 2017-03-11 19:41:24 -0500 | |
commit | 6db72a50f302f6bd3974488a9d681dac26cd72c2 (patch) | |
tree | e4a3764a752654825f30b6064fae4ef49976b3a9 /src/interrupt.rs | |
parent | a9d701ecc888400ac269a55303388f0feec6f294 (diff) | |
download | cortex-m-6db72a50f302f6bd3974488a9d681dac26cd72c2.tar.gz cortex-m-6db72a50f302f6bd3974488a9d681dac26cd72c2.tar.zst cortex-m-6db72a50f302f6bd3974488a9d681dac26cd72c2.zip |
add Mutex.borrow_mut method
Diffstat (limited to 'src/interrupt.rs')
-rw-r--r-- | src/interrupt.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs index 6d84dec..2aff77e 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs @@ -19,6 +19,11 @@ impl<T> Mutex<T> { pub fn borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T { unsafe { &*self.inner.get() } } + + /// Mutably borrows the data for the duration of the critical section + pub fn borrow_mut<'cs>(&self, _ctxt: &'cs mut CriticalSection) -> &'cs mut T { + unsafe { &mut *self.inner.get() } + } } /// Interrupt number @@ -75,14 +80,14 @@ pub struct CriticalSection { /// This as also known as a "critical section". pub fn free<F, R>(f: F) -> R where - F: FnOnce(&CriticalSection) -> R, + F: FnOnce(CriticalSection) -> R, { let primask = ::register::primask::read(); // disable interrupts disable(); - let r = f(&CriticalSection { _0: () }); + let r = f(CriticalSection { _0: () }); // If the interrupts were active before our `disable` call, then re-enable // them. Otherwise, keep them disabled |