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)
|
||||
));
|
||||
|
||||
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`
|
||||
root.push(quote! {
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[allow(unsafe_code)]
|
||||
pub static mut #mangled: [#hidden::#krate::Node<#input>; #capacity] =
|
||||
pub static mut #mangled: [#input; #capacity] =
|
||||
unsafe { #hidden::#krate::uninitialized() };
|
||||
|
||||
});
|
||||
|
||||
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: () }
|
||||
|
||||
|
@ -387,8 +393,12 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
|||
if let Some(index) = slot {
|
||||
let task = ::#__priority::Task::#name;
|
||||
core::ptr::write(
|
||||
#name::BUFFER.get_unchecked_mut(index as usize),
|
||||
#hidden::#krate::Node { baseline: self.baseline(), payload }
|
||||
#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||
payload,
|
||||
);
|
||||
core::ptr::write(
|
||||
#name::BASELINES.get_unchecked_mut(index as usize),
|
||||
self.baseline(),
|
||||
);
|
||||
|
||||
#__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()) {
|
||||
let task = ::#__priority::Task::#name;
|
||||
core::ptr::write(
|
||||
::#name::BUFFER.get_unchecked_mut(index as usize),
|
||||
#hidden::#krate::Node { payload }
|
||||
::#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||
payload,
|
||||
);
|
||||
|
||||
::#__priority::Q::new().claim_mut(t, |q, _| {
|
||||
|
@ -534,8 +544,12 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
|||
let bl = self.baseline() + after;
|
||||
let task = ::__tq::Task::#name;
|
||||
core::ptr::write(
|
||||
::#name::BUFFER.get_unchecked_mut(index as usize),
|
||||
#hidden::#krate::Node { baseline: bl, payload },
|
||||
::#name::PAYLOADS.get_unchecked_mut(index as usize),
|
||||
payload,
|
||||
);
|
||||
core::ptr::write(
|
||||
::#name::BASELINES.get_unchecked_mut(index as usize),
|
||||
bl,
|
||||
);
|
||||
let m = #hidden::#krate::Message {
|
||||
baseline: bl,
|
||||
|
@ -713,18 +727,19 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
|
|||
if cfg!(feature = "timer-queue") {
|
||||
quote! {
|
||||
#__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::HANDLER(#name::Context::new(node.baseline, node.payload));
|
||||
#name::HANDLER(#name::Context::new(baseline, payload));
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#__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::HANDLER(#name::Context::new(node.payload));
|
||||
#name::HANDLER(#name::Context::new(payload));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ extern crate heapless;
|
|||
extern crate typenum;
|
||||
|
||||
mod instant;
|
||||
mod node;
|
||||
mod resource;
|
||||
#[cfg(feature = "timer-queue")]
|
||||
mod tq;
|
||||
|
@ -36,7 +35,6 @@ pub use typenum::consts::*;
|
|||
pub use typenum::{Max, Maximum, Unsigned};
|
||||
|
||||
pub use instant::Instant;
|
||||
pub use node::Node;
|
||||
pub use resource::{Resource, Threshold};
|
||||
#[cfg(feature = "timer-queue")]
|
||||
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