aboutsummaryrefslogtreecommitdiff
path: root/macros/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/util.rs')
-rw-r--r--macros/src/util.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/macros/src/util.rs b/macros/src/util.rs
new file mode 100644
index 00000000..45f1feef
--- /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
+}