aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-10 20:35:52 -0500
committerGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-10 20:35:52 -0500
commit81c9d39ebc8e73baa396a60eb8d9f717a74b96f0 (patch)
treed444eec8a224c0e84da95a02fdf56ebbb6ae6cae /src
parentf2d4e38af794be833f21948a2a4837a2ff4cadd9 (diff)
downloadcortex-m-81c9d39ebc8e73baa396a60eb8d9f717a74b96f0.tar.gz
cortex-m-81c9d39ebc8e73baa396a60eb8d9f717a74b96f0.tar.zst
cortex-m-81c9d39ebc8e73baa396a60eb8d9f717a74b96f0.zip
CsCtxt renamed to CriticalSection. Mutex.lock removed in favor of Mutex.borrow
Diffstat (limited to 'src')
-rw-r--r--src/interrupt.rs21
-rw-r--r--src/peripheral/mod.rs6
2 files changed, 11 insertions, 16 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 95829ca..6d84dec 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -15,14 +15,9 @@ impl<T> Mutex<T> {
}
impl<T> Mutex<T> {
- /// Gets access to the inner data
- ///
- /// NOTE this prevents interrupts handlers from running thus gaining
- /// exclusive access to the processor
- pub fn lock<F, R>(&self, f: F) -> R
- where F: FnOnce(&mut T) -> R
- {
- unsafe { ::interrupt::free(|_| f(&mut *self.inner.get())) }
+ /// Borrows the data for the duration of the critical section
+ pub fn borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T {
+ unsafe { &*self.inner.get() }
}
}
@@ -32,7 +27,6 @@ pub unsafe trait Nr {
fn nr(&self) -> u8;
}
-// FIXME `T` should have some bound: `Send` or `Sync`?
unsafe impl<T> Sync for Mutex<T> {}
/// Disable interrupts, globally
@@ -69,10 +63,10 @@ pub fn enable() {
}
}
-/// Critical section token
+/// Critical section context
///
/// Indicates that you are executing code within a critical section
-pub struct CsCtxt {
+pub struct CriticalSection {
_0: (),
}
@@ -80,14 +74,15 @@ pub struct CsCtxt {
///
/// This as also known as a "critical section".
pub fn free<F, R>(f: F) -> R
- where F: FnOnce(&CsCtxt) -> R
+where
+ F: FnOnce(&CriticalSection) -> R,
{
let primask = ::register::primask::read();
// disable interrupts
disable();
- let r = f(&CsCtxt { _0: () });
+ let r = f(&CriticalSection { _0: () });
// If the interrupts were active before our `disable` call, then re-enable
// them. Otherwise, keep them disabled
diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs
index f47baf5..f9ee217 100644
--- a/src/peripheral/mod.rs
+++ b/src/peripheral/mod.rs
@@ -10,7 +10,7 @@ use core::ptr;
use volatile_register::{RO, RW, WO};
-use interrupt::{CsCtxt, Nr};
+use interrupt::{CriticalSection, Nr};
#[cfg(test)]
mod test;
@@ -69,8 +69,8 @@ impl<T> Peripheral<T> {
}
}
- /// Borrows the peripheral for the duration of the critical section
- pub fn borrow<'cs>(&self, _ctxt: &'cs CsCtxt) -> &'cs T {
+ /// Borrows the peripheral for the duration of a critical section
+ pub fn borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T {
unsafe { &*self.get() }
}