-
Notifications
You must be signed in to change notification settings - Fork 20
Implement a proc-macros threads creation #83
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: main
Are you sure you want to change the base?
Conversation
Implement a proc macro that allows a declaration like: ```rust fn mythread(arg: usize, arg2: &'static Thing) { .. } ``` With this change, creation of threads, with arbitrary "Send" arguments can be done without needing allocation. The macros reserves a static area alongside the `k_thread` structure to use for handing the threads over. This creates a function `mythread` with the given args that returns a ReadyThread. This has a `start()` method which will begin execution of the thread. This results in a RunningThread, which has a join method that can be used to wait for termination. Signed-off-by: David Brown <[email protected]>
Move away from the `kobj_define` task declaration to use the new `#[zephyr::thread]` to define these. This allows for a more natural declaration where the thread just looks like an attribute added to a regular function declaration. This also eliminates the static Mutex, as the Mutex now has a constructor that avoids allocation (it is still put in an Arc, though). Signed-off-by: David Brown <[email protected]>
To help with debugging, try to give created Zephyr threads a readable name. Currently, this is based off of the name of the function used in the declaration of the thread. Signed-off-by: David Brown <[email protected]>
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.
I like it
/// | ||
/// Will block until the thread has terminated. | ||
/// | ||
/// TODO: Allow a timeout? |
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.
It would be smart to allow a timeout and return the integer result.
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.
Actually, would it make more sense to do something similar to what std::thread
does where we return a Result that can be either Ok or an Err? I guess that's more "rustonic" than integer return values 😅
Replace how Zephyr threads are declared in Rust. Provides a proc-macro to make this fairly straightforward:
This function can then be called, and will return a
ReadThread
. This has methods for setting priority, and astart
method, which returns aRunningThread
, which has a join method. The thread can be respawned after it has exited.The thread macro also accepts a
pool_size = nnn
parameter, which will create an array of threads, and can be started that many times.