@@ -19,9 +19,17 @@ unsafe extern "Rust" {
1919 item : * const u8 ,
2020 timeout_us : Option < u32 > ,
2121 ) -> bool ;
22- fn esp_preempt_queue_try_send_to_back ( queue : QueuePtr , item : * const u8 ) -> bool ;
22+ fn esp_preempt_queue_try_send_to_back_from_isr (
23+ queue : QueuePtr ,
24+ item : * const u8 ,
25+ higher_prio_task_waken : Option < & mut bool > ,
26+ ) -> bool ;
2327 fn esp_preempt_queue_receive ( queue : QueuePtr , item : * mut u8 , timeout_us : Option < u32 > ) -> bool ;
24- fn esp_preempt_queue_try_receive ( queue : QueuePtr , item : * mut u8 ) -> bool ;
28+ fn esp_preempt_queue_try_receive_from_isr (
29+ queue : QueuePtr ,
30+ item : * mut u8 ,
31+ higher_prio_task_waken : Option < & mut bool > ,
32+ ) -> bool ;
2533 fn esp_preempt_queue_remove ( queue : QueuePtr , item : * const u8 ) ;
2634 fn esp_preempt_queue_messages_waiting ( queue : QueuePtr ) -> usize ;
2735}
@@ -67,11 +75,18 @@ pub trait QueueImplementation {
6775 ///
6876 /// If the queue is full, this function will immediately return `false`.
6977 ///
78+ /// The `higher_prio_task_waken` parameter is an optional mutable reference to a boolean flag.
79+ /// If the flag is `Some`, the implementation may set it to `true` to request a context switch.
80+ ///
7081 /// # Safety
7182 ///
7283 /// The caller must ensure that `item` can be dereferenced and points to an allocation of
7384 /// a size equal to the queue's item size.
74- unsafe fn try_send_to_back ( queue : QueuePtr , item : * const u8 ) -> bool ;
85+ unsafe fn try_send_to_back_from_isr (
86+ queue : QueuePtr ,
87+ item : * const u8 ,
88+ higher_prio_task_waken : Option < & mut bool > ,
89+ ) -> bool ;
7590
7691 /// Dequeues an item from the queue.
7792 ///
@@ -90,13 +105,20 @@ pub trait QueueImplementation {
90105 ///
91106 /// If the queue is empty, this function will return `false` immediately.
92107 ///
108+ /// The `higher_prio_task_waken` parameter is an optional mutable reference to a boolean flag.
109+ /// If the flag is `Some`, the implementation may set it to `true` to request a context switch.
110+ ///
93111 /// This function returns `true` if the item was successfully dequeued, `false` otherwise.
94112 ///
95113 /// # Safety
96114 ///
97115 /// The caller must ensure that `item` can be dereferenced and points to an allocation of
98116 /// a size equal to the queue's item size.
99- unsafe fn try_receive ( queue : QueuePtr , item : * mut u8 ) -> bool ;
117+ unsafe fn try_receive_from_isr (
118+ queue : QueuePtr ,
119+ item : * mut u8 ,
120+ higher_prio_task_waken : Option < & mut bool > ,
121+ ) -> bool ;
100122
101123 /// Removes an item from the queue.
102124 ///
@@ -151,8 +173,18 @@ macro_rules! register_queue_implementation {
151173
152174 #[ unsafe ( no_mangle) ]
153175 #[ inline]
154- fn esp_preempt_queue_try_send_to_back( queue: QueuePtr , item: * const u8 ) -> bool {
155- unsafe { <$t as $crate:: queue:: QueueImplementation >:: try_send_to_back( queue, item) }
176+ fn esp_preempt_queue_try_send_to_back_from_isr(
177+ queue: QueuePtr ,
178+ item: * const u8 ,
179+ higher_prio_task_waken: Option <& mut bool >,
180+ ) -> bool {
181+ unsafe {
182+ <$t as $crate:: queue:: QueueImplementation >:: try_send_to_back_from_isr(
183+ queue,
184+ item,
185+ higher_prio_task_waken,
186+ )
187+ }
156188 }
157189
158190 #[ unsafe ( no_mangle) ]
@@ -167,8 +199,18 @@ macro_rules! register_queue_implementation {
167199
168200 #[ unsafe ( no_mangle) ]
169201 #[ inline]
170- fn esp_preempt_queue_try_receive( queue: QueuePtr , item: * mut u8 ) -> bool {
171- unsafe { <$t as $crate:: queue:: QueueImplementation >:: try_receive( queue, item) }
202+ fn esp_preempt_queue_try_receive_from_isr(
203+ queue: QueuePtr ,
204+ item: * mut u8 ,
205+ higher_prio_task_waken: Option <& mut bool >,
206+ ) -> bool {
207+ unsafe {
208+ <$t as $crate:: queue:: QueueImplementation >:: try_receive_from_isr(
209+ queue,
210+ item,
211+ higher_prio_task_waken,
212+ )
213+ }
172214 }
173215
174216 #[ unsafe ( no_mangle) ]
@@ -256,12 +298,21 @@ impl QueueHandle {
256298 ///
257299 /// If the queue is full, this function will immediately return `false`.
258300 ///
301+ /// If a higher priority task is woken up by this operation, the `higher_prio_task_waken` flag
302+ /// is set to `true`.
303+ ///
259304 /// # Safety
260305 ///
261306 /// The caller must ensure that `item` can be dereferenced and points to an allocation of
262307 /// a size equal to the queue's item size.
263- pub unsafe fn try_send_to_back ( & self , item : * const u8 ) -> bool {
264- unsafe { esp_preempt_queue_try_send_to_back ( self . 0 , item) }
308+ pub unsafe fn try_send_to_back_from_isr (
309+ & self ,
310+ item : * const u8 ,
311+ higher_priority_task_waken : Option < & mut bool > ,
312+ ) -> bool {
313+ unsafe {
314+ esp_preempt_queue_try_send_to_back_from_isr ( self . 0 , item, higher_priority_task_waken)
315+ }
265316 }
266317
267318 /// Dequeues an item from the queue.
@@ -285,12 +336,19 @@ impl QueueHandle {
285336 ///
286337 /// This function returns `true` if the item was successfully dequeued, `false` otherwise.
287338 ///
339+ /// If a higher priority task is woken up by this operation, the `higher_prio_task_waken` flag
340+ /// is set to `true`.
341+ ///
288342 /// # Safety
289343 ///
290344 /// The caller must ensure that `item` can be dereferenced and points to an allocation of
291345 /// a size equal to the queue's item size.
292- pub unsafe fn try_receive ( & self , item : * mut u8 ) -> bool {
293- unsafe { esp_preempt_queue_try_receive ( self . 0 , item) }
346+ pub unsafe fn try_receive_from_isr (
347+ & self ,
348+ item : * mut u8 ,
349+ higher_priority_task_waken : Option < & mut bool > ,
350+ ) -> bool {
351+ unsafe { esp_preempt_queue_try_receive_from_isr ( self . 0 , item, higher_priority_task_waken) }
294352 }
295353
296354 /// Removes an item from the queue.
0 commit comments