aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-02 10:50:27 -0500
committerGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-02 10:50:27 -0500
commitb4f105cde28d89f3c8e42e4fe341390a7dc2dccf (patch)
treee04482f7e5d112eaf9153d9a646218eb41cb9f8c /src/interrupt.rs
parentfede2074f7fa74e0ab0211bab7af4240954f4e0a (diff)
downloadcortex-m-b4f105cde28d89f3c8e42e4fe341390a7dc2dccf.tar.gz
cortex-m-b4f105cde28d89f3c8e42e4fe341390a7dc2dccf.tar.zst
cortex-m-b4f105cde28d89f3c8e42e4fe341390a7dc2dccf.zip
add a critical section token to `interrupt::free`
Diffstat (limited to 'src/interrupt.rs')
-rw-r--r--src/interrupt.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 035dcd4..edc3dfb 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -22,7 +22,7 @@ impl<T> Mutex<T> {
pub fn lock<F, R>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R
{
- unsafe { ::interrupt::free(|| f(&mut *self.inner.get())) }
+ unsafe { ::interrupt::free(|_| f(&mut *self.inner.get())) }
}
}
@@ -61,16 +61,23 @@ pub unsafe fn enable() {
}
}
+/// Critical section token
+///
+/// Indicates that you are executing code within a critical section
+pub struct CsToken {
+ _private: (),
+}
+
/// Execute closure `f` in an interrupt-free context.
/// This as also known as a "critical section".
pub unsafe fn free<F, R>(f: F) -> R
- where F: FnOnce() -> R
+ where F: FnOnce(&CsToken) -> R
{
let primask = ::register::primask::read();
disable();
- let r = f();
+ let r = f(&CsToken { _private: () });
// If the interrupts were enabled before our `disable` call, then re-enable
// them. Otherwise, keep them disabled