diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2017-07-14 18:54:54 -0500 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2017-07-14 18:57:02 -0500 |
| commit | 98596554b3d88a7619bdbc3ac7462a95b7263e96 (patch) | |
| tree | b04a8e1e6011f741e045044389e6189d49abf78a /macros/src/util.rs | |
| parent | 59afbf02aa06d976dfd22df4cb87fadf6027a0fb (diff) | |
split macro parser into its own crate and improve error handling / reporting
Diffstat (limited to 'macros/src/util.rs')
| -rw-r--r-- | macros/src/util.rs | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/macros/src/util.rs b/macros/src/util.rs deleted file mode 100644 index 4722ca7..0000000 --- a/macros/src/util.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::cmp; -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 by one or more tasks that have the same priority - Owned(u8), - // Shared by tasks with different priorities - Shared(u8), -} - -impl Ceiling { - pub fn is_owned(&self) -> bool { - match *self { - Ceiling::Owned(_) => true, - _ => false, - } - } -} - -pub fn compute_ceilings(app: &App) -> Ceilings { - let mut ceilings = HashMap::new(); - - for resource in &app.idle.resources { - ceilings.insert(resource.clone(), Ceiling::Owned(0)); - } - - for task in app.tasks.values() { - for resource in &task.resources { - if let Some(ceiling) = ceilings.get_mut(resource) { - match *ceiling { - Ceiling::Owned(current) => { - if current == task.priority { - *ceiling = Ceiling::Owned(current); - } else { - *ceiling = Ceiling::Shared( - cmp::max(current, task.priority), - ); - } - } - Ceiling::Shared(old) => { - if task.priority > old { - *ceiling = Ceiling::Shared(task.priority); - } - } - } - - continue; - } - - ceilings.insert(resource.clone(), Ceiling::Owned(task.priority)); - } - } - - ceilings -} |
