The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
Diff: platform/CircularBuffer.h
- Revision:
- 160:5571c4ff569f
- Parent:
- 158:1c57384330a6
- Child:
- 165:d1b4690b3f8b
--- a/platform/CircularBuffer.h Thu Nov 23 11:44:04 2017 +0000 +++ b/platform/CircularBuffer.h Wed Jan 17 16:13:02 2018 +0000 @@ -109,6 +109,23 @@ core_util_critical_section_exit(); } + /** Get the number of elements currently stored in the circular_buffer */ + CounterType size() const { + core_util_critical_section_enter(); + CounterType elements; + if (!_full) { + if (_head < _tail) { + elements = BufferSize + _head - _tail; + } else { + elements = _head - _tail; + } + } else { + elements = BufferSize; + } + core_util_critical_section_exit(); + return elements; + } + private: T _pool[BufferSize]; volatile CounterType _head;