-
Notifications
You must be signed in to change notification settings - Fork 242
Spawn local without attribute #1116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
578bcbf
964642b
c2f5a60
d241893
92137f2
e0d4627
82c9d75
ee5f773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Hello from task1! | ||
| Hello from task2! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #![no_main] | ||
| #![no_std] | ||
|
|
||
| use panic_semihosting as _; | ||
|
|
||
| #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] | ||
| mod app { | ||
| use cortex_m_semihosting::{debug, hprintln}; | ||
| use super::*; | ||
|
|
||
| #[shared] | ||
| struct Shared {} | ||
|
|
||
| #[local] | ||
| struct Local {} | ||
|
|
||
| #[init] | ||
| fn init(_cx: init::Context) -> (Shared, Local) { | ||
| task1::spawn().unwrap(); | ||
| //task2::spawn(Default::default()).ok(); <--- This is rejected since not all args are Send and Sync | ||
| (Shared {}, Local {}) | ||
| } | ||
|
|
||
| #[task(priority = 1)] | ||
| async fn task1(cx: task1::Context) { | ||
| hprintln!("Hello from task1!"); | ||
| cx.local_spawner.task2(Default::default()).unwrap(); | ||
| } | ||
|
|
||
| // Task where some args are !Send/!Sync | ||
| #[task(priority = 1)] | ||
| async fn task2(_cx: task2::Context, _nsns: NotSendNotSync) { | ||
| hprintln!("Hello from task2!"); | ||
| debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default, Debug)] | ||
| struct NotSendNotSync(core::marker::PhantomData<*mut u8>); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // TODO: What should we name this? | ||
|
|
||
| /// Dummy trait which will only ever be implemented where type T is Self | ||
| pub trait Dummy { | ||
|
||
| /// This should always be same as `Self` | ||
| type T; | ||
| fn to(self) -> Self::T; | ||
| } | ||
|
|
||
| impl<T> Dummy for T { | ||
| type T = T; | ||
| fn to(self) -> T { | ||
| self | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #![no_main] | ||
|
|
||
| #[rtic::app(device = lm3s6965, dispatchers = [SSI0, GPIOA])] | ||
| mod app { | ||
| use super::*; | ||
|
|
||
| #[shared] | ||
| struct Shared {} | ||
|
|
||
| #[local] | ||
| struct Local {} | ||
|
|
||
| #[init] | ||
| fn init(_cx: init::Context) -> (Shared, Local) { | ||
| (Shared {}, Local {}) | ||
| } | ||
|
|
||
| #[task(priority = 1)] | ||
| async fn foo(_cx: foo::Context, _nsns: NotSendNotSync) {} | ||
|
|
||
| #[task(priority = 2)] | ||
| async fn bar(cx: bar::Context) { | ||
| cx.local_spawner.foo(Default::default()).ok(); | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default, Debug)] | ||
| struct NotSendNotSync(core::marker::PhantomData<*mut u8>); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| error[E0599]: no method named `foo` found for struct `__rtic_internal_bar_LocalSpawner` in the current scope | ||
| --> ui/spawn-non-send-different-exec.rs:23:26 | ||
| | | ||
| 3 | #[rtic::app(device = lm3s6965, dispatchers = [SSI0, GPIOA])] | ||
| | ------------------------------------------------------------ method `foo` not found for this struct | ||
| ... | ||
| 23 | cx.local_spawner.foo(Default::default()).ok(); | ||
| | ^^^ method not found in `__rtic_internal_bar_LocalSpawner` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #![no_main] | ||
|
|
||
| #[rtic::app(device = lm3s6965, dispatchers = [SSI0])] | ||
| mod app { | ||
| use super::*; | ||
|
|
||
| #[shared] | ||
| struct Shared {} | ||
|
|
||
| #[local] | ||
| struct Local {} | ||
|
|
||
| #[init] | ||
| fn init(_cx: init::Context) -> (Shared, Local) { | ||
| foo::spawn(NotSendNotSync::default()).ok(); | ||
| (Shared {}, Local {}) | ||
| } | ||
|
|
||
| #[task(priority = 1)] | ||
| async fn foo(_cx: foo::Context, _nsns: NotSendNotSync) {} | ||
| } | ||
|
|
||
| #[derive(Default, Debug)] | ||
| struct NotSendNotSync(core::marker::PhantomData<*mut u8>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. For some reason the compiler can not auto demote
&mut Tto&Twhen generics are involved (not sure of the rules here).Without the above fix, we get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying AfoHT's link on matrix: https://doc.rust-lang.org/reference/type-coercions.html#r-coerce.types.mut-reborrow