mirror of https://github.com/ARMmbed/mbed-os.git
CircularBuffer(): get available transactions
This implementation returns the number of available (stored) transactions in the bufferpull/5058/head
parent
e12f116ec1
commit
839cd7ee70
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue