File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ use core::marker::PhantomData;
22
22
use core:: mem:: MaybeUninit ;
23
23
24
24
use crate :: sys:: queue:: Queue ;
25
+ use crate :: time:: Forever ;
25
26
26
27
mod counter;
27
28
@@ -130,7 +131,7 @@ impl<T> Sender<T> {
130
131
}
131
132
SenderFlavor :: Bounded ( chan) => {
132
133
// Retrieve a message buffer from the free list.
133
- let buf = unsafe { chan. free . recv ( ) } ;
134
+ let buf = unsafe { chan. free . recv ( Forever ) } ;
134
135
let buf = buf as * mut Message < T > ;
135
136
unsafe {
136
137
buf. write ( Message :: new ( msg) ) ;
@@ -217,15 +218,15 @@ impl<T> Receiver<T> {
217
218
match & self . flavor {
218
219
ReceiverFlavor :: Unbounded { queue, .. } => {
219
220
let msg = unsafe {
220
- queue. recv ( )
221
+ queue. recv ( Forever )
221
222
} ;
222
223
let msg = msg as * mut Message < T > ;
223
224
let msg = unsafe { Box :: from_raw ( msg) } ;
224
225
Ok ( msg. data )
225
226
}
226
227
ReceiverFlavor :: Bounded ( chan) => {
227
228
let rawbuf = unsafe {
228
- chan. chan . recv ( )
229
+ chan. chan . recv ( Forever )
229
230
} ;
230
231
let buf = rawbuf as * mut Message < T > ;
231
232
let msg: Message < T > = unsafe { buf. read ( ) } ;
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ use zephyr_sys::{
18
18
19
19
#[ cfg( CONFIG_RUST_ALLOC ) ]
20
20
use crate :: error:: Result ;
21
- use crate :: sys:: K_FOREVER ;
22
21
use crate :: object:: { Fixed , StaticKernelObject , Wrapped } ;
22
+ use crate :: time:: Timeout ;
23
23
24
24
/// A wrapper around a Zephyr `k_queue` object.
25
25
pub struct Queue {
@@ -62,8 +62,14 @@ impl Queue {
62
62
/// Get an element from a queue.
63
63
///
64
64
/// This routine removes the first data item from the [`Queue`].
65
- pub unsafe fn recv ( & self ) -> * mut c_void {
66
- k_queue_get ( self . item . get ( ) , K_FOREVER )
65
+ /// The timeout value can be [`Forever`] to block until there is a message, [`NoWait`] to check
66
+ /// and immediately return if there is no message, or a [`Duration`] to indicate a specific
67
+ /// timeout.
68
+ pub unsafe fn recv < T > ( & self , timeout : T ) -> * mut c_void
69
+ where T : Into < Timeout >
70
+ {
71
+ let timeout: Timeout = timeout. into ( ) ;
72
+ k_queue_get ( self . item . get ( ) , timeout. 0 )
67
73
}
68
74
}
69
75
You can’t perform that action at this time.
0 commit comments