mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
wip2
This commit is contained in:
parent
3c208003f5
commit
c360ffaad8
7 changed files with 270 additions and 41 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue