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

Rolling buffer size enhancements, bug fix, and unit tests #2081

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

sirknightj
Copy link
Contributor

@sirknightj sirknightj commented Nov 14, 2024

Issue #, if available:
N/A

What was changed?

  • Add proper size tracking (bug fix), which allows:
    • Able to check if it's at capacity and data will be overwritten.
    • DLOGI("Extract! Size: %d, index: %u, bounds: [%u - %u). Ago=%d", pRollingBuffer->size, index, pRollingBuffer->tailIndex, pRollingBuffer->headIndex, pRollingBuffer->headIndex - index); to check how many elements away from the head of the queue upon request.
  • Handle integer overflow case when indexes wrap around UINT64_MAX.
  • Add documentation for methods
  • Add comments in the code
  • Factored out the range check to a separate method.
  • Added more unit tests to confirm behavior.
  • Make rollingBufferGetSize and rollingBufferIsEmpty thread safe by adding locks.

Why was it changed?

  • Make rolling buffer code more robust and more readable.

How was it changed?

  • Refer to the code above.
  • Note: The size needed to be its own variable because you can remove items from the buffer in an arbitrary order.

What testing was done for the changes?

  • Run the new unit tests and they pass.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant