hujun260 opened a new pull request, #18237:
URL: https://github.com/apache/nuttx/pull/18237
## Summary
This PR consolidates multiple return statements in the `sched_critmonitor()`
function to improve code quality and address static analysis defects.
## Changes
1. **Control Flow Refactoring**: Inverted the condition check from
`task_state != TSTATE_TASK_RUNNING` to `task_state == TSTATE_TASK_RUNNING`
2. **Eliminated Multiple Returns**: Removed early return statement,
consolidating all processing logic into a single conditional block
3. **Improved Readability**: All critical monitoring operations (CPU load
processing, run time tracking, and max run time updates) are now clearly
grouped together
## Rationale
- **MISRA HIS Compliance**: Reduces the number of exit points from a
function (addresses Coverity HIS_metric_violation RETURN defect)
- **Code Quality**: Single return pattern improves code maintainability and
makes control flow more evident
- **Static Analysis**: Eliminates Coverity defect findings related to
multiple return statements
## Impact
- **Stability**: No functional behavior changes; maintains exact same logic
- **Code Quality**: Improved code structure without affecting performance
- **Compatibility**: Fully backward compatible; no breaking changes
- **Files Changed**: 1 file (sched/sched/sched_critmonitor.c)
- Lines changed: 22 lines modified (10 insertions, 12 deletions)
## Verification
The refactored code maintains identical functionality:
- Task state checking remains the same
- CPU load calculations unchanged
- Run time tracking logic preserved
- All operations properly grouped within the conditional block
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]