diff options
author | px4dev <px4@purgatory.org> | 2013-08-04 19:48:46 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-08-04 19:48:46 -0700 |
commit | 1fb4705ab7038fb4b135b49c58f14b48f0cfab48 (patch) | |
tree | 92382da29e4b7e77d49e4b7a27df3b48089b2894 /src/drivers | |
parent | 4b4f33e6a4fb18047a6ca73d3a4872a900519b5c (diff) | |
download | px4-firmware-1fb4705ab7038fb4b135b49c58f14b48f0cfab48.tar.gz px4-firmware-1fb4705ab7038fb4b135b49c58f14b48f0cfab48.tar.bz2 px4-firmware-1fb4705ab7038fb4b135b49c58f14b48f0cfab48.zip |
Add size and flush methods to the ringbuffer class.
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/device/ringbuffer.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/drivers/device/ringbuffer.h b/src/drivers/device/ringbuffer.h index 37686fdbe..dc0c84052 100644 --- a/src/drivers/device/ringbuffer.h +++ b/src/drivers/device/ringbuffer.h @@ -104,6 +104,17 @@ public: */ bool full() { return _next(_head) == _tail; } + /* + * Returns the capacity of the buffer, or zero if the buffer could + * not be allocated. + */ + unsigned size() { return (_buf != nullptr) ? _size : 0; } + + /* + * Empties the buffer. + */ + void flush() { _head = _tail = _size; } + private: T *const _buf; const unsigned _size; @@ -114,11 +125,11 @@ private: }; template <typename T> -RingBuffer<T>::RingBuffer(unsigned size) : - _buf(new T[size + 1]), - _size(size), - _head(size), - _tail(size) +RingBuffer<T>::RingBuffer(unsigned with_size) : + _buf(new T[with_size + 1]), + _size(with_size), + _head(with_size), + _tail(with_size) {} template <typename T> |