Skip to content

Commit 839cd7e

Browse files
authored
CircularBuffer(): get available transactions
This implementation returns the number of available (stored) transactions in the buffer
1 parent e12f116 commit 839cd7e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

platform/CircularBuffer.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,24 @@ class CircularBuffer {
104104
_full = false;
105105
core_util_critical_section_exit();
106106
}
107-
107+
108+
/** Returns the number of available transactions the buffer contains */
109+
CounterType available() {
110+
core_util_critical_section_enter();
111+
CounterType elements;
112+
if (!_full)
113+
{
114+
if (_head < _tail)
115+
elements = BufferSize + _head - _tail;
116+
else
117+
elements = _head - _tail;
118+
}
119+
else
120+
elements = BufferSize;
121+
core_util_critical_section_exit();
122+
return elements;
123+
}
124+
108125
private:
109126
T _pool[BufferSize];
110127
volatile CounterType _head;

0 commit comments

Comments
 (0)