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

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 265d6187e14436ac573a5feee3a263bce2632025
Author: Bowen Wang <[email protected]>
AuthorDate: Mon Jul 6 16:47:32 2026 +0800

    ring: add RING_IDX_OLDEST sentinel for peek helpers
    
    A reader that walks the ring by absolute index needs a way to start from
    the oldest readable position without a valid index in hand.  Add the
    RING_IDX_OLDEST sentinel: a real index never exceeds RTS_IDX_MASK (24
    bits), so this out-of-range value is unambiguous.  When ring_mc_peek()
    sees it in *index it skips ring_clamp_cons() (whose signed compare would
    be meaningless on the sentinel) and starts from the live cons_tail.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 include/nuttx/ring.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/nuttx/ring.h b/include/nuttx/ring.h
index 23b64389480..5a8f74dda91 100644
--- a/include/nuttx/ring.h
+++ b/include/nuttx/ring.h
@@ -172,6 +172,14 @@
 #define RTS_PACK(cnt, idx) \
   ((((uint32_t)(cnt) & 0xff) << RTS_CNT_SHIFT) | ((uint32_t)(idx) & 
RTS_IDX_MASK))
 
+/* Sentinel *index value for the peek helpers: a real index never exceeds
+ * RTS_IDX_MASK (24 bits), so this out-of-range value asks the peek to start
+ * from the oldest readable position (the live cons_tail) instead of clamping
+ * a caller-supplied index.
+ */
+
+#define RING_IDX_OLDEST  UINT32_MAX
+
 #ifndef CACHELINE_SIZE
 #  define CACHELINE_SIZE 64
 #endif
@@ -1182,7 +1190,7 @@ ring_mc_peek(FAR struct ring_s *r, FAR void *items, 
uint32_t count,
       uint32_t available;
 
       cons_index = RTS_IDX(atomic_read_acquire(&r->cons_tail));
-      if (index)
+      if (index && *index != RING_IDX_OLDEST)
         {
           cons_index = ring_clamp_cons(*index, cons_index);
         }

Reply via email to