From b4f105cde28d89f3c8e42e4fe341390a7dc2dccf Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 2 Mar 2017 10:50:27 -0500 Subject: add a critical section token to `interrupt::free` --- src/interrupt.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/interrupt.rs') 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 Mutex { pub fn lock(&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: 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 -- cgit v1.2.3