Refactor counter wrap-around logic into helper function#1
Draft
Refactor counter wrap-around logic into helper function#1
Conversation
- Created calculate_counter_delta() helper function to eliminate duplicated wrap-around logic - Uses UINT32_MAX instead of ULONG_MAX for platform-independent 32-bit counter handling - Applied helper function to all counter calculations (BytesSent/Received, PacketsSent/Received, ErrorsSent, RetransCount, FailedRetransCount, RetryCount, MultipleRetryCount) - Addresses PR rdkcentral#902 feedback about code duplication and counter width handling Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Changed calculate_counter_delta() to use uint32_t instead of unsigned long for platform independence - Moved variable declarations to local scope within each counter calculation block - Added explicit casts to unsigned long for snprintf format compatibility Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Removed explicit wrap-around calculation since unsigned arithmetic naturally handles it - Simplified calculate_counter_delta() to just return current - previous - Updated documentation to reflect this approach Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Added detailed explanation of how unsigned arithmetic handles wrap-around - Included example case to clarify the mechanism Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Enhanced explanation to clarify that the delta represents counter increments - Made it clear that the example shows the counter wrapping from max to 0 to 1 Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Clarified that delta of 2 represents counter increased by 2, not incremented twice - Made the explanation more precise about the wrap transitions Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
- Added build artifacts to .gitignore (Makefiles, config files, .deps directories) - Removed accidentally committed build artifacts from repository Co-authored-by: MothiShree <190452914+MothiShree@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Apply changes based on feedback from review
Refactor counter wrap-around logic into helper function
Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses feedback from PR #902: duplicated wrap-around delta logic and platform-dependent counter width.
Changes
calculate_counter_delta(uint32_t current, uint32_t previous)- static inline, uses unsigned arithmetic's natural modular wrap-arounduint32_tinstead ofunsigned longensures consistent 32-bit semantics regardless of platform word sizeImplementation
Previous approach used explicit wrap-around calculation with
ULONG_MAX, which is 64-bit on 64-bit platforms, causing incorrect delta computation when counters wrap at 32-bit boundary.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.