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 c8479293a663c5800820a0c0eca7eb319f6a74ef Author: Bowen Wang <[email protected]> AuthorDate: Tue Jul 7 17:30:15 2026 +0800 ring: add ring_wrap to normalise a position into the index space A reader that tracks an absolute position and wants to detect whether an overwrite lapped it needs to compare its expected next position against the index a peek reported. The peek returns a 24-bit index, while the expected position is a linear (unwrapped) value, so the two cannot be compared directly without masking. Add ring_wrap(pos) to wrap a linear position into the same 24-bit index space using the public RING_IDX_MASK, so callers avoid reaching into the internal packed layout. Signed-off-by: Bowen Wang <[email protected]> --- include/nuttx/ring.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/nuttx/ring.h b/include/nuttx/ring.h index 5a8f74dda91..8adc8564c89 100644 --- a/include/nuttx/ring.h +++ b/include/nuttx/ring.h @@ -301,6 +301,14 @@ #define ring_data(r) ((FAR char *)((FAR struct ring_s *)(r) + 1)) +/* Wrap a linear (unwrapped) position into the ring's 24-bit index space, + * matching the index the peek helpers return through their *index argument. + * Lets a caller compare an expected next position against the value a peek + * reported without reaching into the internal packed layout. + */ + +#define ring_wrap(pos) ((uint32_t)(pos) & RING_IDX_MASK) + /* ring_spsc_init - lightweight initialization for SPSC mode. * * Unlike ring_init (which uses atomic CAS for multi-core safe
