Skip to content

task + async misc #67

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

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

task + async misc #67

wants to merge 15 commits into from

Conversation

d3zd3z
Copy link
Collaborator

@d3zd3z d3zd3z commented Mar 7, 2025

Create a new proc-macro-based way of declaring threads in Zephyr. Instead of the weird kobj_define macro, provide a zephyr::thread macro that can decorate an ordinary Rust function to become a builder for a ReadyThread that can just be started. Threads can also now be reused after they exit.

This allows something like:

#[zephyr::thread(stack_size = 2048)]
fn mythread(name: &'static str, index: usize) {
    // Body
}

and somewhere in the code, you just call it, which returns a handle that can be used to start the thread.

let joiner = mythread("thename", 42).start();
...
joiner.join();  // Wait for thread to exit, if desired.

There is still some things to clean up, hence the draft, but I wanted to get some exposure.

@d3zd3z
Copy link
Collaborator Author

d3zd3z commented Apr 7, 2025

I'd like to start getting this ready for review. But, there is a question of how much this should be split apart. There are a few cherry-picked changes that are to be merged, so we'll at least wait for those to go in.

@d3zd3z d3zd3z force-pushed the tasks branch 2 times, most recently from 2657f67 to f90442b Compare April 8, 2025 22:02
@d3zd3z d3zd3z requested review from Ablu, teburd and cfriedt and removed request for Ablu April 8, 2025 22:02
@d3zd3z d3zd3z changed the title New Proc-macro thread declaration task + async misc Apr 10, 2025
@d3zd3z d3zd3z marked this pull request as draft April 10, 2025 19:18
@d3zd3z d3zd3z force-pushed the tasks branch 4 times, most recently from cef1d3a to 0f75e9e Compare April 17, 2025 21:35
d3zd3z added 11 commits May 22, 2025 16:15
Don't require that the two time bases be the same.  This allows
applications to work using the default embassy-time base of 1MHz.  There
is a performance cost to the conversion (which depends on the exact
ratios).  If the time bases are the same (which would be common for an
application build for a single target), then no conversion is needed.

Signed-off-by: David Brown <[email protected]>
Don't generate instance access code for DT nodes that aren't actually
enabled.

Signed-off-by: David Brown <[email protected]>
Add a short readme to explain some of the difficulties with level
triggered interrupts (notably, most STM32 devices do not support level
triggered interrupts).

Signed-off-by: David Brown <[email protected]>
A version mismatch here causes compilation errors due to other crates
depending on this specific version.

Signed-off-by: David Brown <[email protected]>
Instead of allocating work queues, and hoping they don't get freed,
instead move to a static declaration.  This is facilitated by a macro
`define_work_queue` that makes it easy to declare these at the top
level.

Signed-off-by: David Brown <[email protected]>
The docgen target seems to try building the docs before the generated
headers are present.  Work around this by making a full build first, and
then generating the docs.

Signed-off-by: David Brown <[email protected]>
The work-queue-based Future has been removed, so also removed the
documentation that was describing it.

Signed-off-by: David Brown <[email protected]>
Fix various broken links in documentation comments.

Signed-off-by: David Brown <[email protected]>
Add some missing methods to `PinWeak`, notably forwarding
`strong_count`, `weak_count`, and `ptr_eq` through to the inner type.

Signed-off-by: David Brown <[email protected]>
After running the work queue benchmarks, ensure that we haven't leaked
any Arcs.

Signed-off-by: David Brown <[email protected]>
First step in generalizing the worker type.  Place the inner pointer
type into a trait, and allow the work methods to work on pointers of
that type.

This continues to work the same as before with `Pin<Arc<Work<T>>>`.  It
needs a bit more massaging to be able to work with static pointers,
namely that the constructor has to be able to be static, and as such,
the initialization can't happen until it has been pinned down.  This
will likely change the "new" API.

Signed-off-by: David Brown <[email protected]>
d3zd3z added 3 commits May 22, 2025 16:15
The ZephyrObject pairs the UnsafeCell with an atomic for initialization
that allows for const constructors.

Signed-off-by: David Brown <[email protected]>
Instead of hard-coding `Pin<Arc<Work<T>>>`, have a constructor that
wraps the `Arc<Work<T>>` in a new type `ArcWork`.  This has the methods
for submitting work on this particular pointer type.

This leaves room for `StaticWork` which will have a static reference.

Removes all references to Pin.  Now that the Work queue itself is stored
in a ZephyrObject, we have a mechanism to panic on move, which although
a runtime check, does catch issues where values have been moved.

Signed-off-by: David Brown <[email protected]>
Support enqueueing &'static Work as well as the Arc-based work.

Signed-off-by: David Brown <[email protected]>
Clean up formatting

Signed-off-by: David Brown <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant