From 9cf7d80bab4176c7e2735eabb648c9a5f0551b8f Mon Sep 17 00:00:00 2001 From: Tiago Medicci Serrano Date: Tue, 10 Feb 2026 09:24:09 -0300 Subject: [PATCH] sched/mqueue: Enable receiving messages on an interrupt handler The internal implementation of `file_mq_receive` did not allow receiving a message from an interrupt handler. Although it is not possible to wait for a message in an interrupt context, it is perfectly possible to retrieve already-existing messages from the message queue. This commit modifies file_mq_timedreceive_internal to enable checking the message list and, if no messages exist, it returns immediately. This enables receiving any existing messages in an interrupt context. Signed-off-by: Tiago Medicci Serrano --- sched/mqueue/mq_receive.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c index 231b4c5d4f4..474fc41e5b6 100644 --- a/sched/mqueue/mq_receive.c +++ b/sched/mqueue/mq_receive.c @@ -145,8 +145,6 @@ ssize_t file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg, irqstate_t flags; ssize_t ret = 0; - DEBUGASSERT(up_interrupt_context() == false); - /* Verify the input parameters */ if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)) @@ -190,6 +188,14 @@ ssize_t file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg, return -EAGAIN; } + /* If we are in interrupt context, return EAGAIN instead of blocking */ + + if (up_interrupt_context()) + { + leave_critical_section(flags); + return -EAGAIN; + } + /* Wait & get the message from the message queue */ ret = nxmq_wait_receive(msgq, &mqmsg, abstime, ticks);