We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d57caa7 commit 619fa4dCopy full SHA for 619fa4d
components/drivers/src/ringbuffer.c
@@ -333,11 +333,15 @@ rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb)
333
return rb->buffer_size;
334
case RT_RINGBUFFER_HALFFULL:
335
default:
336
- if (rb->write_index > rb->read_index)
337
- return rb->write_index - rb->read_index;
+ {
+ rt_size_t wi = rb->write_index, ri = rb->read_index;
338
+
339
+ if (wi > ri)
340
+ return wi - ri;
341
else
- return rb->buffer_size - (rb->read_index - rb->write_index);
- };
342
+ return rb->buffer_size - (ri - wi);
343
+ }
344
345
}
346
RTM_EXPORT(rt_ringbuffer_data_len);
347
0 commit comments