aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/device/ringbuffer.h
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2013-08-04 15:01:11 -0700
committerpx4dev <px4@purgatory.org>2013-08-04 15:01:11 -0700
commit64e856276ef12b74eca0c89a73b32372a47e8522 (patch)
tree162af43d82c15dfe34bb3fcfae613e3f03453db4 /src/drivers/device/ringbuffer.h
parent1cc6235e770d373969aefe93822e32a593bc393e (diff)
parente95861e9df4d4236b07d29c3f086bfa4730e8634 (diff)
downloadpx4-firmware-64e856276ef12b74eca0c89a73b32372a47e8522.tar.gz
px4-firmware-64e856276ef12b74eca0c89a73b32372a47e8522.tar.bz2
px4-firmware-64e856276ef12b74eca0c89a73b32372a47e8522.zip
Merge branch 'fmuv2_bringup' of https://github.com/cvg/Firmware_Private into fmuv2_bringup
Diffstat (limited to 'src/drivers/device/ringbuffer.h')
-rw-r--r--src/drivers/device/ringbuffer.h21
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>