This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 388f89c02 porting/npl/nuttx: Fix event queue timed waits and size
388f89c02 is described below

commit 388f89c027e12676ac232fe60a852fd837cfd6a2
Author: raiden00pl <[email protected]>
AuthorDate: Sat Oct 3 09:30:27 2026 +0200

    porting/npl/nuttx: Fix event queue timed waits and size
    
    Take the event queue depth from CONFIG_NIMBLE_EVENTQ_SIZE. It defaults
    to the previous 16 messages when the option is not defined, so the port
    builds before NuttX adds the Kconfig option.
    
    NuttX NPL time is in milliseconds. Initialize the relative timeout with
    seconds and the millisecond remainder. Return on a failed timed receive
    so a cancelled event cannot keep the loop spinning after its deadline.
    
    Assisted-by: Claude:claude-fable-5-1
    Signed-off-by: raiden00pl <[email protected]>
---
 porting/npl/nuttx/src/os_eventq.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/porting/npl/nuttx/src/os_eventq.c 
b/porting/npl/nuttx/src/os_eventq.c
index a2628cc1b..f443624da 100644
--- a/porting/npl/nuttx/src/os_eventq.c
+++ b/porting/npl/nuttx/src/os_eventq.c
@@ -27,6 +27,12 @@
 
 #include "nimble/nimble_npl.h"
 
+/* Event queue depth; default until NuttX provides the Kconfig option. */
+
+#ifndef CONFIG_NIMBLE_EVENTQ_SIZE
+#define CONFIG_NIMBLE_EVENTQ_SIZE 16
+#endif
+
 static struct ble_npl_eventq dflt_evq =
 {
   .mq = (mqd_t)-1
@@ -45,7 +51,7 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
 {
     char path[PATH_MAX];
     struct mq_attr attr;
-    attr.mq_maxmsg = 16;
+    attr.mq_maxmsg = CONFIG_NIMBLE_EVENTQ_SIZE;
     attr.mq_msgsize = sizeof(struct ble_npl_event*);
     attr.mq_flags = 0;
 
@@ -92,6 +98,7 @@ ble_npl_eventq_get(struct ble_npl_eventq *evq,
                    ble_npl_time_t tmo)
 {
     struct ble_npl_event *ev = NULL;
+    ssize_t ret;
 
     if (tmo == BLE_NPL_TIME_FOREVER)
       {
@@ -106,13 +113,16 @@ ble_npl_eventq_get(struct ble_npl_eventq *evq,
 
         clock_gettime(CLOCK_REALTIME, &now);
 
-        t.tv_sec += tmo / USEC_PER_SEC;
-        t.tv_nsec = (tmo - t.tv_sec) * NSEC_PER_MSEC;
+        t.tv_sec = tmo / MSEC_PER_SEC;
+        t.tv_nsec = (tmo % MSEC_PER_SEC) * NSEC_PER_MSEC;
         clock_timespec_add(&now, &t, &t);
 
         do
           {
-            mq_timedreceive(evq->mq, (char*)&ev, sizeof(ev), NULL, &t);
+            ret = mq_timedreceive(evq->mq, (char *)&ev, sizeof(ev), NULL, &t);
+            if (ret < 0) {
+                return NULL;
+            }
           } while (ev && ev->ev_queued == 0);
       }
 

Reply via email to