This commit is contained in:
Per Lindgren 2020-06-13 00:19:01 +02:00
parent 3c208003f5
commit c360ffaad8
7 changed files with 270 additions and 41 deletions

View file

@ -103,12 +103,12 @@ pub fn codegen(
}
#[inline(always)]
pub unsafe fn is_locked(&self) -> bool {
pub unsafe fn get_locked(&self) -> bool {
self.locked.get()
}
pub unsafe fn lock(&self) {
self.locked.set(true);
pub unsafe fn set_locked(&self, b: bool) {
self.locked.set(b);
}
}
));

View file

@ -71,13 +71,17 @@ pub fn impl_mutex(
#cfg_core
impl<'a> rtic::Mutex for #path<'a> {
type T = #ty;
#[inline(always)]
fn lock<R>(&mut self, f: impl FnOnce(&mut #ty) -> R) -> R {
/// Priority ceiling
const CEILING: u8 = #ceiling;
unsafe {
if unsafe { self.get_locked() } {
panic!("Resource locked in sequential context");
};
unsafe { self.set_locked(true); }
let r = unsafe {
rtic::export::lock(
#ptr,
#priority,
@ -85,7 +89,9 @@ pub fn impl_mutex(
#device::NVIC_PRIO_BITS,
f,
)
}
};
unsafe { self.set_locked(false); }
r
}
}
)