-
Notifications
You must be signed in to change notification settings - Fork 3k
CircularBuffer class modification and test #5578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
platform/CircularBuffer.h
Outdated
@@ -30,21 +30,25 @@ namespace mbed { | |||
* | |||
* @note Synchronization level: Interrupt safe | |||
*/ | |||
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t> | |||
template<typename T, uint32_t BufferSize> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a breaking change; why not use a static assertion rather than removing the template parameter:
MBED_STATIC_ASSERT(
(sizeof(CounterType) >= sizeof(uint32_t)) ||
(BufferSize < (((uint64_t) 1) << (sizeof(CounterType) * 8))),
"Invalid BufferSize for the CounterType"
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertion is an alternative to this solution. I decided to make a proposal with removed template parameter since I can't see any advantage of having it. Why do we need it?
Provided solution is not complete. Also signed counter types should be forbidden. The following declaration is also invalid and will not be caught by the static assertion:
CircularBuffer<int, 255, char> cb;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CounterType
allows user of the class to choose the most appropriate variable type for inner counters of the object; it might save few bytes by CircularBuffer
. It would have been better if the type selection was made automatically based on the buffer size but it is here now and we have to live with it.
Provided solution is not complete. Also signed counter types should be forbidden. The following declaration is also invalid and will not be caught by the static assertion:
CircularBuffer<int, 255, char> cb;
The static assertion can handle the sign of the CounterType
if you define a type traits that determine if an integral type is signed or unsigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are committed to preserving backward compatibility for our user facing APIs for 5.x versions of Mbed OS.
platform/CircularBuffer.h
Outdated
@@ -30,21 +30,25 @@ namespace mbed { | |||
* | |||
* @note Synchronization level: Interrupt safe | |||
*/ | |||
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t> | |||
template<typename T, uint32_t BufferSize> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are committed to preserving backward compatibility for our user facing APIs for 5.x versions of Mbed OS.
platform/CircularBuffer.h
Outdated
@@ -110,9 +118,10 @@ class CircularBuffer { | |||
} | |||
|
|||
/** Get the number of elements currently stored in the circular_buffer */ | |||
CounterType size() const { | |||
uint32_t size() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't change APIs.
3100589
to
9e0d6b1
Compare
Modified this patch. In current version CounterType template parameter stays, but it must be unsigned type consistent with the BufferSize. Test has been also adapted. |
Linking the issue: #5384 |
platform/CircularBuffer.h
Outdated
@@ -18,6 +18,20 @@ | |||
|
|||
#include "platform/mbed_critical.h" | |||
|
|||
/* Detect if CounterType of the Circular buffer is of unsigned type. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put the traits in a namespace named internal within the mbed namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as suggested.
CounterType is used to define type of _head and _tail counters. This may cause the following problems: - counters are used as array indexes so only unsigned types should be used for counters, - CounterType must be consistent with BufferSize and BufferSize is of uint32_t type (i.e. Circular Buffer with the following parameters: BufferSize = 1000, CounterType = unsigned char will not work properly).
9e0d6b1
to
a488424
Compare
@mprse What was updated, please state to let reviewers aware this is ready for another round |
I provided responses to review comments. All change requests have been processed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SenRamakri ping
/morph build |
Build : SUCCESSBuild number : 663 Triggering tests/morph test |
Test : SUCCESSBuild number : 489 |
Exporter Build : SUCCESSBuild number : 305 |
This PR just broke all our Ci builds.
Provided fix in #5748 |
Sorry for missing |
Thanks @SeppoTakalo . How come our all CI did not catch this one? |
@0xc0170 The cliapp that is build in the PR contains copy&paste from CircularBuffer. The build that broke, is my test branch (soon to be merged to master), and there I have removed the CircularBuffer and I use the one from Mbed OS. |
Description
This PR provides:
Status
READY
Migrations
NO