mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
sys: lib: introduce ringbuffer_remove()
This commit adds a function that deletes n elements from the ringbuffer without actually writing them somewhere.
This commit is contained in:
parent
b7fc0df5d3
commit
e4257284ad
@ -86,6 +86,14 @@ int ringbuffer_get_one(ringbuffer_t *restrict rb);
|
|||||||
*/
|
*/
|
||||||
unsigned ringbuffer_get(ringbuffer_t *restrict rb, char *buf, unsigned n);
|
unsigned ringbuffer_get(ringbuffer_t *restrict rb, char *buf, unsigned n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove a number of elements from the ringbuffer.
|
||||||
|
* @param[in,out] rb Ringbuffer to operate on.
|
||||||
|
* @param[in] n Read at most n elements.
|
||||||
|
* @returns Number of elements actually removed.
|
||||||
|
*/
|
||||||
|
unsigned ringbuffer_remove(ringbuffer_t *restrict rb, unsigned n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Test if the ringbuffer is empty.
|
* @brief Test if the ringbuffer is empty.
|
||||||
* @param[in,out] rb Ringbuffer to operate on.
|
* @param[in,out] rb Ringbuffer to operate on.
|
||||||
|
@ -102,6 +102,25 @@ unsigned ringbuffer_get(ringbuffer_t *restrict rb, char *buf, unsigned n)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned ringbuffer_remove(ringbuffer_t *restrict rb, unsigned n)
|
||||||
|
{
|
||||||
|
if (n > rb->avail) {
|
||||||
|
n = rb->avail;
|
||||||
|
rb->start = rb->avail = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb->start -= n;
|
||||||
|
rb->avail -= n;
|
||||||
|
|
||||||
|
/* compensate underflow */
|
||||||
|
if (rb->start > rb->size) {
|
||||||
|
rb->start += rb->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
int ringbuffer_peek_one(const ringbuffer_t *restrict rb_)
|
int ringbuffer_peek_one(const ringbuffer_t *restrict rb_)
|
||||||
{
|
{
|
||||||
ringbuffer_t rb = *rb_;
|
ringbuffer_t rb = *rb_;
|
||||||
|
Loading…
Reference in New Issue
Block a user