aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/interrupt.rs21
-rw-r--r--src/peripheral/mod.rs6
3 files changed, 17 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5289b6f..cdf3795 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Execution context primitives: execution context `Local` data and `Token`s to
identify execution contexts.
+- A `borrow` method to `Mutex` that replaces `lock`. This method returns a `&-`
+ reference.
+
### Changed
- [breaking-change] `StackFrame` has been renamed to `StackedRegisters` and
@@ -45,6 +48,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `vector_table` and its associated `struct`, `VectorTable`. It's not a good
idea to give people a simple way to call the exception handlers.
+- `Mutex`'s `lock` method as it's unsound. You can use it to get multiple `&mut
+ -` references to the data.
+
## [v0.1.6] - 2017-01-22
### Added
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() }
}