diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2017-04-21 15:41:03 -0500 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2017-04-21 15:41:03 -0500 |
| commit | 1c82f1b1190cb40a3502d5b74a8c98775a788850 (patch) | |
| tree | 4157ac304a4b372e7e4a79daaecf06e7a5c78664 | |
| parent | 3e165f2a42b8f3c66e3e77742a54feb875ec4bd6 (diff) | |
raise_to -> Ceiling.raise
| -rw-r--r-- | src/lib.rs | 47 | ||||
| -rw-r--r-- | tests/cfail/borrow.rs | 2 | ||||
| -rw-r--r-- | tests/cfail/ceiling.rs | 2 | ||||
| -rw-r--r-- | tests/cfail/lock.rs | 8 | ||||
| -rw-r--r-- | tests/cfail/race-1.rs | 2 | ||||
| -rw-r--r-- | tests/cfail/race-2.rs | 4 |
6 files changed, 31 insertions, 34 deletions
@@ -522,31 +522,6 @@ where r } -/// Raises the system ceiling to match `resource`'s ceiling -#[cfg(not(thumbv6m))] -pub fn raise_to<R, CURRENT, HIGHER, RES, F>( - _current_ceiling: &C<CURRENT>, - _resource: &RES, - f: F, -) -> R -where - F: FnOnce(&C<HIGHER>) -> R, - RES: ResourceLike<Ceiling = HIGHER>, - HIGHER: Cmp<CURRENT, Output = Greater>, - HIGHER: Cmp<UMAX, Output = Less>, - HIGHER: Unsigned, -{ - unsafe { - let old_basepri = basepri::read(); - basepri_max::write(logical2hw(HIGHER::to_u8())); - barrier!(); - let ret = f(&C { _marker: PhantomData }); - barrier!(); - basepri::write(old_basepri); - ret - } -} - /// Requests the execution of a `task` pub fn request<T, PRIORITY>(_task: fn(T, P<PRIORITY>)) where @@ -586,6 +561,28 @@ pub struct C<T> { _marker: PhantomData<T>, } +impl<CURRENT> C<CURRENT> { + /// Raises the ceiling to match `resource`'s ceiling + pub fn raise<HIGHER, RES, R, F>(&self, _resource: &'static RES, f: F) -> R + where + RES: ResourceLike<Ceiling = HIGHER>, + HIGHER: Cmp<CURRENT, Output = Greater>, + HIGHER: Cmp<UMAX, Output = Less>, + HIGHER: Unsigned, + F: FnOnce(&C<HIGHER>) -> R, + { + unsafe { + let old_basepri = basepri::read(); + basepri_max::write(logical2hw(HIGHER::to_u8())); + barrier!(); + let ret = f(&C { _marker: PhantomData }); + barrier!(); + basepri::write(old_basepri); + ret + } + } +} + /// A type-level priority pub struct P<T> { _marker: PhantomData<T>, diff --git a/tests/cfail/borrow.rs b/tests/cfail/borrow.rs index d72402d..14762dc 100644 --- a/tests/cfail/borrow.rs +++ b/tests/cfail/borrow.rs @@ -12,7 +12,7 @@ static R6: Resource<i32, C2> = Resource::new(0); fn j1(prio: P2) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R1, |ceil| { + ceil.raise(&R1, |ceil| { // CAN borrow a resource with ceiling C when the current ceiling SC > C let r2 = R2.borrow(&prio, ceil); diff --git a/tests/cfail/ceiling.rs b/tests/cfail/ceiling.rs index bd6e296..8bbd1f7 100644 --- a/tests/cfail/ceiling.rs +++ b/tests/cfail/ceiling.rs @@ -7,7 +7,7 @@ static R1: Resource<(), C3> = Resource::new(()); fn j1(prio: P2) { let ceil = prio.as_ceiling(); - let c3 = rtfm::raise_to(ceil, &R1, |ceil| { + let c3 = ceil.raise(&R1, |ceil| { // forbidden: ceiling token can't outlive critical section ceil //~ error }); diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index 60a441c..36541f2 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -8,7 +8,7 @@ static R1: Resource<i32, C2> = Resource::new(0); fn j1(prio: P3) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R1, |ceil| { + ceil.raise(&R1, |ceil| { //~^ error }); } @@ -18,7 +18,7 @@ fn j1(prio: P3) { fn j2(prio: P2) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R1, |_| {}); + ceil.raise(&R1, |_| {}); //~^ error // OK @@ -30,7 +30,7 @@ fn j3(prio: P1) { let ceil = prio.as_ceiling(); // OK - rtfm::raise_to(ceil, &R1, |ceil| { + ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); }) } @@ -41,7 +41,7 @@ static R2: Resource<i32, C16> = Resource::new(0); fn j4(prio: P1) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R2, |ceil| { + ceil.raise(&R2, |ceil| { //~^ error }); } diff --git a/tests/cfail/race-1.rs b/tests/cfail/race-1.rs index 0b32c5e..e9d030d 100644 --- a/tests/cfail/race-1.rs +++ b/tests/cfail/race-1.rs @@ -7,7 +7,7 @@ static R1: Resource<i32, C2> = Resource::new(0); fn j1(prio: P1) { let ceil = prio.as_ceiling(); - rtfm::raise_to(&ceil, &R1, |ceil| { + ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); // Would preempt this critical section diff --git a/tests/cfail/race-2.rs b/tests/cfail/race-2.rs index 7f3504d..55dedb6 100644 --- a/tests/cfail/race-2.rs +++ b/tests/cfail/race-2.rs @@ -8,7 +8,7 @@ static R2: Resource<i32, C4> = Resource::new(0); fn j1(prio: P1) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R1, |ceil| { + ceil.raise(&R1, |ceil| { let r1 = R1.borrow(&prio, ceil); // Would preempt this critical section @@ -19,7 +19,7 @@ fn j1(prio: P1) { fn j2(prio: P3) { let ceil = prio.as_ceiling(); - rtfm::raise_to(ceil, &R2, |ceil| { + ceil.raise(&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); |
