diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2017-07-04 11:26:11 -0500 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2017-07-04 11:26:11 -0500 |
| commit | 86a360a3964ecb04a37c0424c76d7b43a9fd40fe (patch) | |
| tree | cbf0ebee17a588f8f004bdd27e590ee6c958761b /macros/src/util.rs | |
| parent | 2bf5401439df4494b33ef87201ee013eb1f167e8 (diff) | |
rtfm! macro take 2
Diffstat (limited to 'macros/src/util.rs')
| -rw-r--r-- | macros/src/util.rs | 48 |
1 files changed, 48 insertions, 0 deletions
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<Ident, Ceiling>; + +#[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 +} |
