Skip to content

Commit 589d76e

Browse files
authored
Merge pull request #5058 from 0x6d61726b/patch-2
CircularBuffer(): get available transactions
2 parents 82f5b58 + 830db6a commit 589d76e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

platform/CircularBuffer.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ class CircularBuffer {
109109
core_util_critical_section_exit();
110110
}
111111

112+
/** Get the number of elements currently stored in the circular_buffer */
113+
CounterType size() const {
114+
core_util_critical_section_enter();
115+
CounterType elements;
116+
if (!_full) {
117+
if (_head < _tail) {
118+
elements = BufferSize + _head - _tail;
119+
} else {
120+
elements = _head - _tail;
121+
}
122+
} else {
123+
elements = BufferSize;
124+
}
125+
core_util_critical_section_exit();
126+
return elements;
127+
}
128+
112129
private:
113130
T _pool[BufferSize];
114131
volatile CounterType _head;

0 commit comments

Comments
 (0)