CircularBuffer(): get available transactions

This implementation returns the number of available (stored) transactions in the buffer
pull/5058/head
0x6d61726b 2017-09-08 15:33:14 +02:00 committed by GitHub
parent e12f116ec1
commit 839cd7ee70
1 changed files with 18 additions and 1 deletions

View File

@ -104,7 +104,24 @@ public:
_full = false;
core_util_critical_section_exit();
}
/** Returns the number of available transactions the buffer contains */
CounterType available() {
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;