Browse Source

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.
mission-4.1.18
Murilo Belluzzo 9 years ago committed by Lucas De Marchi
parent
commit
f7f203efa9
  1. 5
      libraries/AP_HAL/utility/RingBuffer.cpp
  2. 3
      libraries/AP_HAL/utility/RingBuffer.h

5
libraries/AP_HAL/utility/RingBuffer.cpp

@ -36,6 +36,11 @@ uint32_t ByteBuffer::available(void) const @@ -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;

3
libraries/AP_HAL/utility/RingBuffer.h

@ -35,6 +35,9 @@ public: @@ -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;

Loading…
Cancel
Save