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.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/macros/src/util.rs b/macros/src/util.rs
index 45f1feef..4722ca7d 100644
--- a/macros/src/util.rs
+++ b/macros/src/util.rs
@@ -1,3 +1,4 @@
+use std::cmp;
use std::collections::HashMap;
use syn::Ident;
@@ -8,13 +9,18 @@ pub type Ceilings = HashMap<Ident, Ceiling>;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Ceiling {
- Owned,
+ // 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 {
- *self == Ceiling::Owned
+ match *self {
+ Ceiling::Owned(_) => true,
+ _ => false,
+ }
}
}
@@ -22,14 +28,22 @@ pub fn compute_ceilings(app: &App) -> Ceilings {
let mut ceilings = HashMap::new();
for resource in &app.idle.resources {
- ceilings.insert(resource.clone(), Ceiling::Owned);
+ 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 => *ceiling = Ceiling::Shared(task.priority),
+ 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);
@@ -40,7 +54,7 @@ pub fn compute_ceilings(app: &App) -> Ceilings {
continue;
}
- ceilings.insert(resource.clone(), Ceiling::Owned);
+ ceilings.insert(resource.clone(), Ceiling::Owned(task.priority));
}
}