diff options
author | 2018-11-04 18:50:42 +0100 | |
---|---|---|
committer | 2018-11-04 18:50:42 +0100 | |
commit | 37a0692a0fe5d9b41b65728d496b6856a1152dcc (patch) | |
tree | beb91d9c1caa0fb5e16e61236b6b92739766edd2 /macros/src/analyze.rs | |
parent | 16d473a9b6827aa7ffa9ce92e4e532eff9a091d2 (diff) | |
download | rtic-37a0692a0fe5d9b41b65728d496b6856a1152dcc.tar.gz rtic-37a0692a0fe5d9b41b65728d496b6856a1152dcc.tar.zst rtic-37a0692a0fe5d9b41b65728d496b6856a1152dcc.zip |
impl Mutex on all shared resources
document how to write generic code that operates on resources
Diffstat (limited to 'macros/src/analyze.rs')
-rw-r--r-- | macros/src/analyze.rs | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/macros/src/analyze.rs b/macros/src/analyze.rs index 04b462fa..869b5d20 100644 --- a/macros/src/analyze.rs +++ b/macros/src/analyze.rs @@ -30,13 +30,14 @@ pub struct Analysis { pub enum Ownership { // NOTE priorities and ceilings are "logical" (0 = lowest priority, 255 = highest priority) Owned { priority: u8 }, + CoOwned { priority: u8 }, Shared { ceiling: u8 }, } impl Ownership { pub fn needs_lock(&self, priority: u8) -> bool { match *self { - Ownership::Owned { .. } => false, + Ownership::Owned { .. } | Ownership::CoOwned { .. } => false, Ownership::Shared { ceiling } => { debug_assert!(ceiling >= priority); @@ -44,6 +45,13 @@ impl Ownership { } } } + + pub fn is_owned(&self) -> bool { + match *self { + Ownership::Owned { .. } => true, + _ => false, + } + } } pub struct Dispatcher { @@ -72,18 +80,24 @@ pub fn app(app: &App) -> Analysis { for (priority, res) in app.resource_accesses() { if let Some(ownership) = ownerships.get_mut(res) { match *ownership { - Ownership::Owned { priority: ceiling } | Ownership::Shared { ceiling } => { - if priority != ceiling { - *ownership = Ownership::Shared { - ceiling: cmp::max(ceiling, priority), - }; - - let res = &app.resources[res]; - if res.mutability.is_none() { - assert_sync.insert(res.ty.clone()); - } + Ownership::Owned { priority: ceiling } + | Ownership::CoOwned { priority: ceiling } + | Ownership::Shared { ceiling } + if priority != ceiling => + { + *ownership = Ownership::Shared { + ceiling: cmp::max(ceiling, priority), + }; + + let res = &app.resources[res]; + if res.mutability.is_none() { + assert_sync.insert(res.ty.clone()); } } + Ownership::Owned { priority: ceiling } if ceiling == priority => { + *ownership = Ownership::CoOwned { priority }; + } + _ => {} } continue; |