From 86a360a3964ecb04a37c0424c76d7b43a9fd40fe Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 4 Jul 2017 11:26:11 -0500 Subject: rtfm! macro take 2 --- macros/src/util.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 macros/src/util.rs (limited to 'macros/src/util.rs') diff --git a/macros/src/util.rs b/macros/src/util.rs new file mode 100644 index 0000000..45f1fee --- /dev/null +++ b/macros/src/util.rs @@ -0,0 +1,48 @@ +use std::collections::HashMap; + +use syn::Ident; + +use syntax::App; + +pub type Ceilings = HashMap; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Ceiling { + Owned, + Shared(u8), +} + +impl Ceiling { + pub fn is_owned(&self) -> bool { + *self == Ceiling::Owned + } +} + +pub fn compute_ceilings(app: &App) -> Ceilings { + let mut ceilings = HashMap::new(); + + for resource in &app.idle.resources { + ceilings.insert(resource.clone(), Ceiling::Owned); + } + + for task in app.tasks.values() { + for resource in &task.resources { + if let Some(ceiling) = ceilings.get_mut(resource) { + match *ceiling { + Ceiling::Owned => *ceiling = Ceiling::Shared(task.priority), + Ceiling::Shared(old) => { + if task.priority > old { + *ceiling = Ceiling::Shared(task.priority); + } + } + } + + continue; + } + + ceilings.insert(resource.clone(), Ceiling::Owned); + } + } + + ceilings +} -- cgit v1.2.3