Skip to content

Commit 089d2ef

Browse files
authored
Merge branch 'zephyrproject-rtos:main' into main
2 parents a1a3ca7 + e53f6de commit 089d2ef

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ ${module}.path = \"$CACHE{RUST_MODULE_DIR}/${module}\"
129129
# symlink) in the source directory to allow various IDE tools and such to work. The build we
130130
# invoke will override these settings, in case they are out of date. Everything set here
131131
# should match the arguments given to the cargo build command below.
132-
file(WRITE ${SAMPLE_CARGO_CONFIG} "
132+
file(GENERATE OUTPUT ${SAMPLE_CARGO_CONFIG} CONTENT "
133133
# This is a generated sample .cargo/config.toml file from the Zephyr build.
134134
# At the time of generation, this represented the settings needed to allow
135135
# a `cargo build` command to compile the rust code using the current Zephyr build.

zephyr/src/thread.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use zephyr_sys::{
2424

2525
use crate::{
2626
align::AlignAs,
27+
error::to_result_void,
2728
sys::{K_FOREVER, K_NO_WAIT},
29+
time::{Forever, Timeout},
2830
};
2931

3032
/// Adjust a given requested stack size up for the alignment. This is just the stack, and the
@@ -249,20 +251,26 @@ pub struct RunningThread {
249251
}
250252

251253
impl RunningThread {
254+
/// Wait, with timeout, for this thread to finish executing.
255+
///
256+
/// Will block until either the thread terminates, or the timeout occurrs.
257+
pub fn join_timeout<T>(&self, timeout: T) -> crate::Result<()>
258+
where
259+
T: Into<Timeout>,
260+
{
261+
let timeout: Timeout = timeout.into();
262+
let ret = unsafe { k_thread_join(self.id, timeout.0) };
263+
to_result_void(ret)
264+
}
265+
252266
/// Wait for this thread to finish executing.
253267
///
254268
/// Will block until the thread has terminated.
255269
///
256270
/// TODO: Allow a timeout?
257271
/// TODO: Should we try to return a value?
258-
pub fn join(&self) {
259-
unsafe {
260-
// TODO: Can we do something meaningful with the result?
261-
k_thread_join(self.id, K_FOREVER);
262-
263-
// TODO: Ideally, we could put the thread state back to avoid the need for another join
264-
// check when re-allocating the thread.
265-
}
272+
pub fn join(&self) -> crate::Result<()> {
273+
self.join_timeout(Forever)
266274
}
267275
}
268276

0 commit comments

Comments
 (0)