-
Notifications
You must be signed in to change notification settings - Fork 242
Add local tasks #1108
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
Open
usbalbin
wants to merge
16
commits into
rtic-rs:master
Choose a base branch
from
Dectron-AB:spawn-local
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add local tasks #1108
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5bb3ba9
Add the concept of local tasks with an example
usbalbin f10d2b9
Add test for spawning a local task from a different prio
usbalbin 8fbf8a9
Add test for spawning a local task from init
usbalbin 355b478
Add passing test for local task with non Send/Sync arg
usbalbin 518dfae
Fix spawn-local-no-send-sync
usbalbin d9fe447
Rename `is_local_task` to just `local_task` and allow omitting the value
usbalbin 1e8c175
Move example and remove success test
usbalbin 025460b
Update tests for - Rename `is_local_task` to just `local_task` and al…
usbalbin 5e658e4
Move tests to rtic/ui
usbalbin 96b5a81
Revert fmt
usbalbin 266ddd1
Use `is_multiple_of`
datdenkikniet f5e8694
task-reference-in-spawn has new format in 1.90
datdenkikniet 09598ad
Add exit to example
usbalbin a599039
Fix example
usbalbin 7f1521b
Fix example
usbalbin 7f7c0d4
Update changelog
usbalbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Hello from task1! | ||
| Hello from task2! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #![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 it is a local task | ||
| (Shared {}, Local {}) | ||
| } | ||
|
|
||
| #[task(priority = 1)] | ||
| async fn task1(cx: task1::Context) { | ||
| hprintln!("Hello from task1!"); | ||
| cx.local_spawner.task2(Default::default()).unwrap(); | ||
| } | ||
|
|
||
| #[task(priority = 1, local_task = true)] | ||
| 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>); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #![no_main] | ||
|
|
||
| #[rtic::app(device = lm3s6965, dispatchers = [SSI0, GPIOA])] | ||
| mod app { | ||
| #[shared] | ||
| struct Shared {} | ||
|
|
||
| #[local] | ||
| struct Local {} | ||
|
|
||
| #[init] | ||
| fn init(_cx: init::Context) -> (Shared, Local) { | ||
| (Shared {}, Local {}) | ||
| } | ||
|
|
||
| #[task(priority = 1, local_task)] | ||
| async fn foo(_cx: foo::Context) {} | ||
|
|
||
| #[task(priority = 2)] | ||
| async fn bar(cx: bar::Context) { | ||
| cx.local_spawner.foo().ok(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| error[E0609]: no field `local_spawner` on type `__rtic_internal_bar_Context<'_>` | ||
| --> ui/spawn-local-different-exec.rs:21:12 | ||
| | | ||
| 21 | cx.local_spawner.foo().ok(); | ||
| | ^^^^^^^^^^^^^ unknown field | ||
| | | ||
| = note: available field is: `__rtic_internal_p` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@korken89
As is now, we need the attribute to know if it is safe to skip the check for Send/Sync. The global spawn would be unsafe to call with !Send/!Sync args. But I get the feeling that I do not quite understand :)
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.
As for always populating the local spawner with tasks of same prio, sure absolutely! Should the task also have itself in its local spawner?
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.
The local spawn will have
!Send, while the global spawn will always requireSend- as global spawn can never know which one is calling it.So the only ones that can alleviate the
Sendrequirements will be the local spawns.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.
Yes, and right now this is enforced by this assert which is emitted for all
send_typesfrom above, right?This PR removes the assert and the global spawn only for the tasks marked with the attribute. If we remove the attribute then how will the macro know when it should skip generating the assert and global spawn?
We could emit where clauses on the global spawn function which checks that all the arguments impl Send + Sync like this:
However that fails to compile with !Send/Sync even if not calling the types since we are using concrete types.
When creating dummy trait as done in my comment. This defers the compile error to when the function is called. This would, I think, do the same thing as the assert but only at the call site. This way we can replace the asserts with where clauses and then just always emit all the global spawn functions since it will be impossible to call them with !Send/!Sync types.
Or do you have something different in mind?