mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-26 13:39:41 +01:00
split [Node] into [Payload] and [Baseline]
This commit is contained in:
parent
71b68164fa
commit
09c2e99989
4 changed files with 31 additions and 32 deletions
|
@ -308,19 +308,25 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
));
|
));
|
||||||
|
|
||||||
let mangled = Ident::from(format!("_ZN{}{}6BUFFERE", name.as_ref().len(), name));
|
let mangled = Ident::from(format!("_ZN{}{}6PAYLOADSE", name.as_ref().len(), name));
|
||||||
|
|
||||||
// NOTE must be in the root because of `#input`
|
// NOTE must be in the root because of `#input`
|
||||||
root.push(quote! {
|
root.push(quote! {
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub static mut #mangled: [#hidden::#krate::Node<#input>; #capacity] =
|
pub static mut #mangled: [#input; #capacity] =
|
||||||
unsafe { #hidden::#krate::uninitialized() };
|
unsafe { #hidden::#krate::uninitialized() };
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mod_.push(quote! {
|
mod_.push(quote! {
|
||||||
pub use ::#mangled as BUFFER;
|
pub use ::#mangled as PAYLOADS;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
pub static mut BASELINES: [#krate::Instant; #capacity] = unsafe {
|
||||||
|
#krate::uninitialized()
|
||||||
|
};
|
||||||
|
|
||||||
pub struct SQ { _0: () }
|
pub struct SQ { _0: () }
|
||||||
|
|
||||||
|
@ -387,8 +393,12 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
||||||
if let Some(index) = slot {
|
if let Some(index) = slot {
|
||||||
let task = ::#__priority::Task::#name;
|
let task = ::#__priority::Task::#name;
|
||||||
core::ptr::write(
|
core::ptr::write(
|
||||||
#name::BUFFER.get_unchecked_mut(index as usize),
|
#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||||
#hidden::#krate::Node { baseline: self.baseline(), payload }
|
payload,
|
||||||
|
);
|
||||||
|
core::ptr::write(
|
||||||
|
#name::BASELINES.get_unchecked_mut(index as usize),
|
||||||
|
self.baseline(),
|
||||||
);
|
);
|
||||||
|
|
||||||
#__priority::Q::new().claim_mut(t, |q, _| {
|
#__priority::Q::new().claim_mut(t, |q, _| {
|
||||||
|
@ -448,8 +458,8 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
||||||
::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()) {
|
::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()) {
|
||||||
let task = ::#__priority::Task::#name;
|
let task = ::#__priority::Task::#name;
|
||||||
core::ptr::write(
|
core::ptr::write(
|
||||||
::#name::BUFFER.get_unchecked_mut(index as usize),
|
::#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||||
#hidden::#krate::Node { payload }
|
payload,
|
||||||
);
|
);
|
||||||
|
|
||||||
::#__priority::Q::new().claim_mut(t, |q, _| {
|
::#__priority::Q::new().claim_mut(t, |q, _| {
|
||||||
|
@ -533,10 +543,14 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
||||||
::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()) {
|
::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()) {
|
||||||
let bl = self.baseline() + after;
|
let bl = self.baseline() + after;
|
||||||
let task = ::__tq::Task::#name;
|
let task = ::__tq::Task::#name;
|
||||||
core::ptr::write(
|
core::ptr::write(
|
||||||
::#name::BUFFER.get_unchecked_mut(index as usize),
|
::#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||||
#hidden::#krate::Node { baseline: bl, payload },
|
payload,
|
||||||
);
|
);
|
||||||
|
core::ptr::write(
|
||||||
|
::#name::BASELINES.get_unchecked_mut(index as usize),
|
||||||
|
bl,
|
||||||
|
);
|
||||||
let m = #hidden::#krate::Message {
|
let m = #hidden::#krate::Message {
|
||||||
baseline: bl,
|
baseline: bl,
|
||||||
index,
|
index,
|
||||||
|
@ -713,18 +727,19 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
||||||
if cfg!(feature = "timer-queue") {
|
if cfg!(feature = "timer-queue") {
|
||||||
quote! {
|
quote! {
|
||||||
#__priority::Task::#name => {
|
#__priority::Task::#name => {
|
||||||
let node = core::ptr::read(::#name::BUFFER.get_unchecked(index as usize));
|
let payload = core::ptr::read(::#name::PAYLOADS.get_unchecked(index as usize));
|
||||||
|
let baseline = core::ptr::read(::#name::BASELINES.get_unchecked(index as usize));
|
||||||
#name::SQ::get().split().0.enqueue_unchecked(index);
|
#name::SQ::get().split().0.enqueue_unchecked(index);
|
||||||
#name::HANDLER(#name::Context::new(node.baseline, node.payload));
|
#name::HANDLER(#name::Context::new(baseline, payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
#__priority::Task::#name => {
|
#__priority::Task::#name => {
|
||||||
let node = core::ptr::read(::#name::BUFFER.get_unchecked(index as usize));
|
let payload = core::ptr::read(::#name::PAYLOADS.get_unchecked(index as usize));
|
||||||
#name::SQ::get().split().0.enqueue_unchecked(index);
|
#name::SQ::get().split().0.enqueue_unchecked(index);
|
||||||
#name::HANDLER(#name::Context::new(node.payload));
|
#name::HANDLER(#name::Context::new(payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ extern crate heapless;
|
||||||
extern crate typenum;
|
extern crate typenum;
|
||||||
|
|
||||||
mod instant;
|
mod instant;
|
||||||
mod node;
|
|
||||||
mod resource;
|
mod resource;
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
mod tq;
|
mod tq;
|
||||||
|
@ -36,7 +35,6 @@ pub use typenum::consts::*;
|
||||||
pub use typenum::{Max, Maximum, Unsigned};
|
pub use typenum::{Max, Maximum, Unsigned};
|
||||||
|
|
||||||
pub use instant::Instant;
|
pub use instant::Instant;
|
||||||
pub use node::Node;
|
|
||||||
pub use resource::{Resource, Threshold};
|
pub use resource::{Resource, Threshold};
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
pub use tq::{dispatch, Message, TimerQueue};
|
pub use tq::{dispatch, Message, TimerQueue};
|
||||||
|
|
14
src/node.rs
14
src/node.rs
|
@ -1,14 +0,0 @@
|
||||||
use core::cmp::Ordering;
|
|
||||||
use core::{mem, ptr};
|
|
||||||
|
|
||||||
use instant::Instant;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct Node<T>
|
|
||||||
where
|
|
||||||
T: 'static,
|
|
||||||
{
|
|
||||||
#[cfg(feature = "timer-queue")]
|
|
||||||
pub baseline: Instant,
|
|
||||||
pub payload: T,
|
|
||||||
}
|
|
Loading…
Reference in a new issue