casaroli commented on code in PR #21910:
URL: https://github.com/apache/nuttx/pull/21910#discussion_r4596283925


##########
audio/audio.c:
##########
@@ -1564,11 +1582,22 @@ static inline void audio_sendmsg(FAR struct 
audio_upperhalf_s *upper,
   FAR struct audio_openpriv_s *priv;
   pollevent_t eventset;
   irqstate_t flags;
+  bool intr = up_interrupt_context();
+
+  /* In a thread, file_mq_send() can wait for room in a full queue and can
+   * allocate the message: send under the mutex, not under the spinlock.
+   * In an interrupt handler it never waits.
+   */
+
+  if (!intr)
+    {
+      nxmutex_lock(&upper->mqlock);
+    }
 
   flags = spin_lock_irqsave_nopreempt(&upper->spinlock);
   for (priv = upper->head; priv != NULL; priv = priv->flink)
     {
-      if (priv->usermq != NULL)
+      if (intr && priv->usermq != NULL)
         {
           file_mq_send(priv->usermq, (FAR const char *)msg, sizeof(*msg),

Review Comment:
   In a thread, this PR already calls file_mq_send() after the spinlock is 
released, under the new mutex upper->mqlock. Under the spinlock it now sends 
only in an interrupt handler, and there file_mq_send() never waits: with a full 
queue it returns -EAGAIN also without O_NONBLOCK (sched/mqueue/mq_send.c:345), 
and the message comes from the interrupt free list, not from the heap 
(sched/mqueue/mq_send.c:170).
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to