@@ -24,7 +24,9 @@ use zephyr_sys::{
24
24
25
25
use crate :: {
26
26
align:: AlignAs ,
27
+ error:: to_result_void,
27
28
sys:: { K_FOREVER , K_NO_WAIT } ,
29
+ time:: { Forever , Timeout } ,
28
30
} ;
29
31
30
32
/// Adjust a given requested stack size up for the alignment. This is just the stack, and the
@@ -249,20 +251,26 @@ pub struct RunningThread {
249
251
}
250
252
251
253
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
+
252
266
/// Wait for this thread to finish executing.
253
267
///
254
268
/// Will block until the thread has terminated.
255
269
///
256
270
/// TODO: Allow a timeout?
257
271
/// 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 )
266
274
}
267
275
}
268
276
0 commit comments