diff options
author | 2017-03-02 10:50:27 -0500 | |
---|---|---|
committer | 2017-03-02 10:50:27 -0500 | |
commit | b4f105cde28d89f3c8e42e4fe341390a7dc2dccf (patch) | |
tree | e04482f7e5d112eaf9153d9a646218eb41cb9f8c /src/interrupt.rs | |
parent | fede2074f7fa74e0ab0211bab7af4240954f4e0a (diff) | |
download | cortex-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.rs | 13 |
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 |