Skip to content

Commit 6db72a5

Browse files
author
Jorge Aparicio
committed
add Mutex.borrow_mut method
1 parent a9d701e commit 6db72a5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/interrupt.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ impl<T> Mutex<T> {
1919
pub fn borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T {
2020
unsafe { &*self.inner.get() }
2121
}
22+
23+
/// Mutably borrows the data for the duration of the critical section
24+
pub fn borrow_mut<'cs>(&self, _ctxt: &'cs mut CriticalSection) -> &'cs mut T {
25+
unsafe { &mut *self.inner.get() }
26+
}
2227
}
2328

2429
/// Interrupt number
@@ -75,14 +80,14 @@ pub struct CriticalSection {
7580
/// This as also known as a "critical section".
7681
pub fn free<F, R>(f: F) -> R
7782
where
78-
F: FnOnce(&CriticalSection) -> R,
83+
F: FnOnce(CriticalSection) -> R,
7984
{
8085
let primask = ::register::primask::read();
8186

8287
// disable interrupts
8388
disable();
8489

85-
let r = f(&CriticalSection { _0: () });
90+
let r = f(CriticalSection { _0: () });
8691

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

0 commit comments

Comments
 (0)