mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
drop global critical sections in checked::Resource
This commit is contained in:
parent
185f368d63
commit
6ac2625a75
1 changed files with 8 additions and 17 deletions
|
@ -10,25 +10,16 @@ use vcell::VolatileCell;
|
||||||
use Ceiling;
|
use Ceiling;
|
||||||
|
|
||||||
unsafe fn acquire(locked: &VolatileCell<bool>, ceiling: u8) -> u8 {
|
unsafe fn acquire(locked: &VolatileCell<bool>, ceiling: u8) -> u8 {
|
||||||
interrupt::free(
|
assert!(!locked.get(), "resource already locked");
|
||||||
|_| {
|
let old_basepri = basepri::read();
|
||||||
assert!(!locked.get(), "resource already locked");
|
basepri_max::write(ceiling);
|
||||||
let old_basepri = basepri::read();
|
locked.set(true);
|
||||||
basepri_max::write(ceiling);
|
old_basepri
|
||||||
locked.set(true);
|
|
||||||
old_basepri
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn release(locked: &VolatileCell<bool>, old_basepri: u8) {
|
unsafe fn release(locked: &VolatileCell<bool>, old_basepri: u8) {
|
||||||
// XXX Is it really memory safe to *not* use a global critical section here
|
locked.set(false);
|
||||||
// interrupt::free(
|
basepri::write(old_basepri);
|
||||||
// |_| {
|
|
||||||
locked.set(false);
|
|
||||||
basepri::write(old_basepri);
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A totally safe `Resource` that panics on misuse
|
/// A totally safe `Resource` that panics on misuse
|
||||||
|
@ -70,7 +61,7 @@ where
|
||||||
/// Mutably locks the resource, blocking tasks with priority equal or
|
/// Mutably locks the resource, blocking tasks with priority equal or
|
||||||
/// smaller than the ceiling `C`
|
/// smaller than the ceiling `C`
|
||||||
pub fn lock_mut<R, F>(&'static self, f: F) -> R
|
pub fn lock_mut<R, F>(&'static self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut T) -> R,
|
F: FnOnce(&mut T) -> R,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue