Skip to content
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

[core/cyclicbuffer] : buffer reads should not let the tail exceed the head. #1552

Closed
wants to merge 14 commits into from

Conversation

msieben
Copy link
Contributor

@msieben msieben commented Mar 28, 2024

Custom lengths should consider (maximum) distance between tail and head.

… head.

Custom lengths should consider (maximum) distance between tail and head.
@msieben msieben requested review from pwielders and MFransen69 March 28, 2024 13:30
@@ -366,7 +366,7 @@ namespace Core {
break;
}

Cursor cursor(*this, oldTail, length);
Cursor cursor(*this, oldTail, std::min(length, result));
Copy link
Contributor

@pwielders pwielders Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am hoping that this is not needed. Length should always be oke. It could be that after line 363 more data was written into the cyclic buffer and it is up to the consumer of the cursor (GetReadSize() in line 370) to see if he want to read it. The only restriction for this Consumer is the amount of data that can be stored into the passed in Read Buffer with length " length". So I do not think this change fixes any usecase, potentially it only slows down the read process casue now if during line 364 and 370 more data is added to the cyclic buffer it is not treated as being available, where the consumer of the cursor in line 370 might now conclude that it can not read that data as the buffer to store it in is to small (limited to the amount of data that was available at line 363) but maybe the read required 2 or more writes for a full frame to load.
Is there a uses case that is now fixed with this change? If so I would like to evaluate that use-case.

Copy link
Contributor Author

@msieben msieben Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have to clarify, perhaps, offline. I believe I shared the reasoning with @MFransen69 via our internal communication medium. If memory serves me right it relates to the memcpy a few code lines further. I will share that reasoning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @msieben I cannot remember we discussed this in too much detail, so better indeed to share it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MFransen69 I already shared the transcript with @pwielders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@msieben msieben Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pwielders, if analysis is correct and performance is paramount then an ASSERT might be used instead since the std::min is equivalent to a comparison and assignment (a = (b < c ? b : c)), and, the comparison suffices (ASSERT(b < c)).

@msieben msieben requested a review from VeithMetro May 24, 2024 10:44
@VeithMetro
Copy link
Contributor

@msieben I am not sure if this is still necessary after our latest changes to CyclicBuffer from this commit: 9cd25af

If your analysis indicates that there could be a problem, maybe we could write a quick test to prove that there might in fact be an issue in a specific corner case? Even if it turns out there is no problem after the newest changes, this test could still prove useful in the future to prevent some potential issues 😄

@msieben
Copy link
Contributor Author

msieben commented Jun 26, 2024

Closing PR. Low priority. More information at https://jira.rdkcentral.com/jira/browse/METROL-979

@msieben msieben closed this Jun 26, 2024
@pwielders pwielders deleted the development/cyclicbuffer-tail-beyond-head branch October 11, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants