mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
rename borrow to access
This commit is contained in:
parent
296c88c49c
commit
d0ddc322e3
7 changed files with 83 additions and 82 deletions
37
tests/cfail/access.rs
Normal file
37
tests/cfail/access.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
extern crate cortex_m_rtfm as rtfm;
|
||||
|
||||
use rtfm::{C1, C2, C3, C4, C5, P2, Resource};
|
||||
|
||||
static R1: Resource<i32, C4> = Resource::new(0);
|
||||
static R2: Resource<i32, C3> = Resource::new(0);
|
||||
static R3: Resource<i32, C4> = Resource::new(0);
|
||||
static R4: Resource<i32, C5> = Resource::new(0);
|
||||
static R5: Resource<i32, C1> = Resource::new(0);
|
||||
static R6: Resource<i32, C2> = Resource::new(0);
|
||||
|
||||
fn j1(prio: P2) {
|
||||
let ceil = prio.as_ceiling();
|
||||
|
||||
ceil.raise(
|
||||
&R1, |ceil| {
|
||||
// NOTE SC = System Ceiling, P = task Priority
|
||||
|
||||
// CAN access a resource with ceiling RC when SC > RC
|
||||
let r2 = R2.access(&prio, ceil);
|
||||
|
||||
// CAN access a resource with ceiling RC when SC == RC
|
||||
let r3 = R3.access(&prio, ceil);
|
||||
|
||||
// CAN'T access a resource with ceiling RC when SC < RC
|
||||
let r4 = R4.access(&prio, ceil);
|
||||
//~^ error
|
||||
|
||||
// CAN'T access a resource with ceiling RC when RC < P
|
||||
let r5 = R5.access(&prio, ceil);
|
||||
//~^ error
|
||||
|
||||
// CAN access a resource with ceiling RC when RC == P
|
||||
let r6 = R6.access(&prio, ceil);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
extern crate cortex_m_rtfm as rtfm;
|
||||
|
||||
use rtfm::{C1, C2, C3, C4, C5, P2, Resource};
|
||||
|
||||
static R1: Resource<i32, C4> = Resource::new(0);
|
||||
static R2: Resource<i32, C3> = Resource::new(0);
|
||||
static R3: Resource<i32, C4> = Resource::new(0);
|
||||
static R4: Resource<i32, C5> = Resource::new(0);
|
||||
static R5: Resource<i32, C1> = Resource::new(0);
|
||||
static R6: Resource<i32, C2> = Resource::new(0);
|
||||
|
||||
fn j1(prio: P2) {
|
||||
let ceil = prio.as_ceiling();
|
||||
|
||||
ceil.raise(
|
||||
&R1, |ceil| {
|
||||
// NOTE CC = Current Ceiling, P = task Priority
|
||||
|
||||
// CAN borrow a resource with ceiling RC when CC > RC
|
||||
let r2 = R2.borrow(&prio, ceil);
|
||||
|
||||
// CAN borrow a resource with ceiling RC when CC == RC
|
||||
let r3 = R3.borrow(&prio, ceil);
|
||||
|
||||
// CAN'T borrow a resource with ceiling RC when CC < RC
|
||||
let r4 = R4.borrow(&prio, ceil);
|
||||
//~^ error
|
||||
|
||||
// CAN'T borrow a resource with ceiling RC when RC < P
|
||||
let r5 = R5.borrow(&prio, ceil);
|
||||
//~^ error
|
||||
|
||||
// CAN borrow a resource with ceiling RC when RC == P
|
||||
let r6 = R6.borrow(&prio, ceil);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ fn j1(prio: P2) {
|
|||
);
|
||||
|
||||
// Would be bad: lockless access to a resource with ceiling = 3
|
||||
let r2 = R1.borrow(&prio, c3);
|
||||
let r2 = R1.access(&prio, c3);
|
||||
}
|
||||
|
||||
fn j2(prio: P0) {
|
||||
|
|
@ -27,5 +27,5 @@ fn j2(prio: P0) {
|
|||
);
|
||||
|
||||
// Would be bad: lockless access to a resource with ceiling = 16
|
||||
let r1 = R1.borrow(&prio, c16);
|
||||
let r1 = R1.access(&prio, c16);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn j2(prio: P2) {
|
|||
//~^ error
|
||||
|
||||
// OK
|
||||
let r1 = R1.borrow(&prio, ceil);
|
||||
let r1 = R1.access(&prio, ceil);
|
||||
}
|
||||
|
||||
// You CAN access a resource with ceiling C from a task with priority P if C > P
|
||||
|
|
@ -30,7 +30,7 @@ fn j3(prio: P1) {
|
|||
let ceil = prio.as_ceiling();
|
||||
|
||||
// OK
|
||||
ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); })
|
||||
ceil.raise(&R1, |ceil| { let r1 = R1.access(&prio, ceil); })
|
||||
}
|
||||
|
||||
static R2: Resource<i32, C16> = Resource::new(0);
|
||||
|
|
@ -46,5 +46,5 @@ fn j4(prio: P1) {
|
|||
// Only tasks with priority P16 can access a resource with ceiling C16
|
||||
fn j5(prio: P16) {
|
||||
// OK
|
||||
let r2 = R2.borrow(&prio, prio.as_ceiling());
|
||||
let r2 = R2.access(&prio, prio.as_ceiling());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ fn j1(prio: P1) {
|
|||
|
||||
ceil.raise(
|
||||
&R1, |ceil| {
|
||||
let r1 = R1.borrow(&prio, ceil);
|
||||
let r1 = R1.access(&prio, ceil);
|
||||
|
||||
// `j2` preempts this critical section
|
||||
rtfm::request(j2);
|
||||
|
|
@ -22,7 +22,7 @@ fn j2(_task: Task, prio: P3) {
|
|||
|ceil| {
|
||||
// OK C2 (R1's ceiling) <= C16 (system ceiling)
|
||||
// BAD C2 (R1's ceiling) < P3 (j2's priority)
|
||||
let r1 = R1.borrow(&prio, &ceil);
|
||||
let r1 = R1.access(&prio, &ceil);
|
||||
//~^ error
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ fn j1(prio: P1) {
|
|||
|
||||
ceil.raise(
|
||||
&R1, |ceil| {
|
||||
let r1 = R1.borrow(&prio, ceil);
|
||||
let r1 = R1.access(&prio, ceil);
|
||||
|
||||
// `j2` preempts this critical section
|
||||
rtfm::request(j2);
|
||||
|
|
@ -25,7 +25,7 @@ fn j2(_task: Task, prio: P3) {
|
|||
&R2, |ceil| {
|
||||
// OK C2 (R1's ceiling) <= C4 (system ceiling)
|
||||
// BAD C2 (R1's ceiling) < P3 (j2's priority)
|
||||
let r1 = R1.borrow(&prio, ceil);
|
||||
let r1 = R1.access(&prio, ceil);
|
||||
//~^ error
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue