RingBuffer: Add ::clear() method to discard the buffer content

The same could be achieved with ::set_size(::get_size()), but was not
obvious and hurts code readability.
This commit is contained in:
Murilo Belluzzo 2016-07-29 18:05:52 -03:00 committed by Lucas De Marchi
parent 75a1b102fb
commit f7f203efa9
2 changed files with 8 additions and 0 deletions

View File

@ -36,6 +36,11 @@ uint32_t ByteBuffer::available(void) const
return ((head > (_tail=tail))? (size - head) + _tail: _tail - head);
}
void ByteBuffer::clear(void)
{
head = tail = 0;
}
uint32_t ByteBuffer::space(void) const
{
uint32_t _head = head;

View File

@ -35,6 +35,9 @@ public:
// number of bytes available to be read
uint32_t available(void) const;
// Discards the buffer content, emptying it.
void clear(void);
// number of bytes space available to write
uint32_t space(void) const;