aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-18 20:03:22 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-18 20:03:22 -0500
commit97a7e38db7eb0643a6334aba30077622d09e5c85 (patch)
treea561e574a8cb36b748c84f69ee679fe0e61f1899
parenta2b0c9e0d077870441ecdea00108c3a3a394fd9b (diff)
downloadrtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.gz
rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.zst
rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.zip
tasks / idle have exclusive access to Threshold, but do not own the token
-rw-r--r--macros/src/trans.rs4
-rw-r--r--src/lib.rs8
-rw-r--r--tests/cfail/duplicated-handler.rs4
-rw-r--r--tests/cfail/local-token.rs44
-rw-r--r--tests/cfail/lock.rs4
-rw-r--r--tests/cfail/priority-too-high.rs2
-rw-r--r--tests/cfail/priority-too-low.rs2
-rw-r--r--tests/cfail/token-outlive.rs4
-rw-r--r--tests/cfail/token-transfer.rs2
-rw-r--r--tests/cfail/wrong-threshold.rs4
10 files changed, 61 insertions, 17 deletions
diff --git a/macros/src/trans.rs b/macros/src/trans.rs
index 4d51840f..ef224c19 100644
--- a/macros/src/trans.rs
+++ b/macros/src/trans.rs
@@ -50,8 +50,8 @@ fn idle(
.iter()
.all(|resource| ownerships[resource].is_owned())
{
- tys.push(quote!(#krate::Threshold));
- exprs.push(quote!(unsafe { #krate::Threshold::new(0) }));
+ tys.push(quote!(&mut #krate::Threshold));
+ exprs.push(quote!(unsafe { &mut #krate::Threshold::new(0) }));
}
if !app.idle.locals.is_empty() {
diff --git a/src/lib.rs b/src/lib.rs
index c1c7c8f7..a4cfbec8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -221,10 +221,10 @@ macro_rules! task {
#[allow(non_snake_case)]
#[no_mangle]
pub unsafe extern "C" fn $NAME() {
- let f: fn($crate::Threshold, ::$NAME::Resources) = $body;
+ let f: fn(&mut $crate::Threshold, ::$NAME::Resources) = $body;
f(
- $crate::Threshold::new(::$NAME::$NAME),
+ &mut $crate::Threshold::new(::$NAME::$NAME),
::$NAME::Resources::new(),
);
}
@@ -240,7 +240,7 @@ macro_rules! task {
#[no_mangle]
pub unsafe extern "C" fn $NAME() {
let f: fn(
- $crate::Threshold,
+ &mut $crate::Threshold,
&mut $local,
::$NAME::Resources,
) = $body;
@@ -250,7 +250,7 @@ macro_rules! task {
};
f(
- $crate::Threshold::new(::$NAME::$NAME),
+ &mut $crate::Threshold::new(::$NAME::$NAME),
&mut LOCAL,
::$NAME::Resources::new(),
);
diff --git a/tests/cfail/duplicated-handler.rs b/tests/cfail/duplicated-handler.rs
index cae5d8a5..dc902041 100644
--- a/tests/cfail/duplicated-handler.rs
+++ b/tests/cfail/duplicated-handler.rs
@@ -28,8 +28,8 @@ fn idle() -> ! {
task!(EXTI0, exti0);
-fn exti0(_t: Threshold, _r: EXTI0::Resources) {}
+fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
task!(EXTI0, exti1);
-fn exti1(_t: Threshold, _r: EXTI0::Resources) {}
+fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {}
diff --git a/tests/cfail/local-token.rs b/tests/cfail/local-token.rs
new file mode 100644
index 00000000..4c98956b
--- /dev/null
+++ b/tests/cfail/local-token.rs
@@ -0,0 +1,44 @@
+#![deny(warnings)]
+#![feature(const_fn)]
+#![feature(proc_macro)]
+
+#[macro_use(task)]
+extern crate cortex_m_rtfm as rtfm;
+extern crate stm32f103xx;
+
+use rtfm::{app, Threshold};
+
+app! {
+ device: stm32f103xx,
+
+ tasks: {
+ EXTI0: {
+ enabled: true,
+ priority: 1,
+ },
+ }
+}
+
+fn init(_p: init::Peripherals) {}
+
+fn idle() -> ! {
+ loop {}
+}
+
+task!(EXTI0, exti0, Old {
+ token: Option<Threshold> = None;
+});
+
+fn exti0(nt: &mut Threshold, old: &mut Old, _r: EXTI0::Resources) {
+ if let Some(ot) = old.token.take() {
+ let _: (Threshold, Threshold) = (*nt, ot);
+ //~^ error cannot move out of borrowed content
+
+ return
+ }
+
+ // ERROR can't store a threshold token in a local variable, otherwise you
+ // would end up with two threshold tokens in a task (see `if let` above)
+ old.token = Some(*nt);
+ //~^ error cannot move out of borrowed content
+}
diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs
index f93b79aa..736027e2 100644
--- a/tests/cfail/lock.rs
+++ b/tests/cfail/lock.rs
@@ -45,7 +45,7 @@ fn idle() -> ! {
task!(EXTI0, exti0);
-fn exti0(mut t: Threshold, r: EXTI0::Resources) {
+fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) {
// OK need to lock to access the resource
if r.STATE.claim(&mut t, |state, _| **state) {}
@@ -55,7 +55,7 @@ fn exti0(mut t: Threshold, r: EXTI0::Resources) {
task!(EXTI1, exti1);
-fn exti1(mut t: Threshold, r: EXTI1::Resources) {
+fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) {
// ERROR no need to lock. Has direct access because priority == ceiling
if r.STATE.claim(&mut t, |state, _| **state) {
//~^ error no method named `claim` found for type
diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs
index ac3a7043..c76b7a6b 100644
--- a/tests/cfail/priority-too-high.rs
+++ b/tests/cfail/priority-too-high.rs
@@ -26,4 +26,4 @@ fn idle() -> ! {
task!(SYS_TICK, sys_tick);
-fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {}
+fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}
diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs
index 8bb08017..1e0c8e92 100644
--- a/tests/cfail/priority-too-low.rs
+++ b/tests/cfail/priority-too-low.rs
@@ -26,4 +26,4 @@ fn idle() -> ! {
task!(SYS_TICK, sys_tick);
-fn sys_tick(_: Threshold, _: SYS_TICK::Resources) {}
+fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {}
diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs
index 9bcd2882..93d1c604 100644
--- a/tests/cfail/token-outlive.rs
+++ b/tests/cfail/token-outlive.rs
@@ -38,7 +38,7 @@ fn idle() -> ! {
task!(EXTI0, exti0);
-fn exti0(mut t: Threshold, r: EXTI0::Resources) {
+fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) {
// ERROR token should not outlive the critical section
let t = r.STATE.claim(&mut t, |_state, t| t);
//~^ error cannot infer an appropriate lifetime
@@ -46,4 +46,4 @@ fn exti0(mut t: Threshold, r: EXTI0::Resources) {
task!(EXTI1, exti1);
-fn exti1(_t: Threshold, _r: EXTI1::Resources) {}
+fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {}
diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs
index e517a6bf..91e74bdf 100644
--- a/tests/cfail/token-transfer.rs
+++ b/tests/cfail/token-transfer.rs
@@ -32,4 +32,4 @@ fn idle() -> ! {
task!(EXTI0, exti0);
-fn exti0(_t: Threshold, _r: EXTI0::Resources) {}
+fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs
index af8bb05d..39d3a57b 100644
--- a/tests/cfail/wrong-threshold.rs
+++ b/tests/cfail/wrong-threshold.rs
@@ -39,7 +39,7 @@ fn idle() -> ! {
task!(EXTI0, exti0);
-fn exti0(mut ot: Threshold, r: EXTI0::Resources) {
+fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) {
r.A.claim(&mut ot, |_a, mut _it| {
//~^ error cannot borrow `ot` as mutable more than once at a time
//~| error cannot borrow `ot` as mutable more than once at a time
@@ -50,4 +50,4 @@ fn exti0(mut ot: Threshold, r: EXTI0::Resources) {
task!(EXTI1, exti1);
-fn exti1(_t: Threshold, r: EXTI1::Resources) {}
+fn exti1(_t: &mut Threshold, r: EXTI1::Resources) {}