split [Node] into [Payload] and [Baseline]

This commit is contained in:
Jorge Aparicio 2018-05-07 22:05:19 +02:00
parent 71b68164fa
commit 09c2e99989
4 changed files with 31 additions and 32 deletions

View file

@ -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, _| {
@ -534,8 +544,12 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens {
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,
@ -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));
} }
} }
} }

View file

@ -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};

View file

@ -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,
}