From 839cd7ee70bd7f47bf79d16f80c095db587f0d90 Mon Sep 17 00:00:00 2001 From: 0x6d61726b <0x6d61726b@gmail.com> Date: Fri, 8 Sep 2017 15:33:14 +0200 Subject: [PATCH 1/4] CircularBuffer(): get available transactions This implementation returns the number of available (stored) transactions in the buffer --- platform/CircularBuffer.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/platform/CircularBuffer.h b/platform/CircularBuffer.h index bb7fd38c54..84491d2a75 100644 --- a/platform/CircularBuffer.h +++ b/platform/CircularBuffer.h @@ -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; From 69e6f11c2dd50948327a15b43246fc8993b99725 Mon Sep 17 00:00:00 2001 From: 0x6d61726b <0x6d61726b@gmail.com> Date: Thu, 5 Oct 2017 20:47:31 +0200 Subject: [PATCH 2/4] updates according to comments in pull request --- platform/CircularBuffer.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/CircularBuffer.h b/platform/CircularBuffer.h index 84491d2a75..ff05f5497c 100644 --- a/platform/CircularBuffer.h +++ b/platform/CircularBuffer.h @@ -104,9 +104,10 @@ public: _full = false; core_util_critical_section_exit(); } - - /** Returns the number of available transactions the buffer contains */ - CounterType available() { + + /** Get the number of elements currently stored in the circular_buffer */ + CounterType size() const + { core_util_critical_section_enter(); CounterType elements; if (!_full) From c1ab43ce76743e1225e54f59930e7268701b9e32 Mon Sep 17 00:00:00 2001 From: 0x6d61726b <0x6d61726b@gmail.com> Date: Fri, 20 Oct 2017 22:06:01 +0200 Subject: [PATCH 3/4] Code style updated --- platform/CircularBuffer.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/platform/CircularBuffer.h b/platform/CircularBuffer.h index ff05f5497c..be3545f54d 100644 --- a/platform/CircularBuffer.h +++ b/platform/CircularBuffer.h @@ -106,19 +106,20 @@ public: } /** Get the number of elements currently stored in the circular_buffer */ - CounterType size() const - { + CounterType size() const { core_util_critical_section_enter(); CounterType elements; - if (!_full) - { - if (_head < _tail) + if (!_full) { + if (_head < _tail) { elements = BufferSize + _head - _tail; - else + } + else { elements = _head - _tail; + } } - else + else { elements = BufferSize; + } core_util_critical_section_exit(); return elements; } From 830db6a5a0966185bc3fd28e49e6d8789cc0bc03 Mon Sep 17 00:00:00 2001 From: 0x6d61726b <0x6d61726b@gmail.com> Date: Tue, 31 Oct 2017 16:07:33 +0100 Subject: [PATCH 4/4] code style adopted --- platform/CircularBuffer.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/platform/CircularBuffer.h b/platform/CircularBuffer.h index be3545f54d..3e0bc92574 100644 --- a/platform/CircularBuffer.h +++ b/platform/CircularBuffer.h @@ -112,12 +112,10 @@ public: if (!_full) { if (_head < _tail) { elements = BufferSize + _head - _tail; - } - else { + } else { elements = _head - _tail; } - } - else { + } else { elements = BufferSize; } core_util_critical_section_exit();