Merge pull request #5058 from 0x6d61726b/patch-2

CircularBuffer(): get available transactions
pull/5471/head
Martin Kojtal 2017-11-09 16:54:59 +00:00 committed by GitHub
commit 589d76e59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -109,6 +109,23 @@ public:
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;