hujun260 opened a new pull request, #18213:
URL: https://github.com/apache/nuttx/pull/18213
## Summary
Eliminate goto-based control flow in the `nxsem_tickwait()` function by
replacing
it with structured if-else blocks to achieve MISRA HIS compliance while
maintaining
identical functional behavior and improving code readability.
## Motivation and Problem
The original implementation used goto statements to handle control flow and
resource
cleanup, which violates MISRA HIS coding standards for safety-critical
systems.
These standards promote structured programming with single entry and exit
points
to improve code verification and reduce defects. Replacing goto with
structured
if-else blocks improves code clarity, verifiability, and compliance with
automotive
safety standards.
## Changes
- Replace early return goto with inverted condition check (ret != OK)
- Replace timeout handling goto with nested if-else structure
- Move timeout and semaphore wait logic into properly nested blocks
- Eliminate the out: label and centralize exit at function end
- Maintain identical semantics: critical section is still entered/exited
correctly
## Impact
- **Compliance**: Achieves MISRA HIS compliance for goto elimination metrics
- **Code Quality**: Improved readability with structured control flow
- **Verifiability**: Easier static analysis and formal verification
- **Maintainability**: Clear control flow without label jumps
- **Backward Compatibility**: No functional changes; identical runtime
behavior
- **Performance**: No performance impact; compiler optimizations identical
## Verification
- [x] Code compiles without warnings on ARM GCC 10.x
- [x] Verified on QEMU ARMv7-A simulator with multimedia profile
- [x] Semaphore tickwait operations verified:
- Immediate success case (tryait succeeds)
- Zero delay timeout case
- Waiting with watchdog timer case
- [x] Critical section protection verified (interrupts disabled during
operation)
- [x] Watchdog timer start and cancel verified
- [x] Static analysis shows improved compliance metrics
## Testing
Tested with:
- ARM GCC 10.x compiler
- QEMU ARMv7-A simulation
- Semaphore tickwait scenarios:
- Semaphore available (immediate return)
- Zero delay timeout
- Waiting with timeout and watchdog protection
- Interrupt safety during critical sections
## Files Changed
- `sched/semaphore/sem_tickwait.c` (42 lines: 17 insertions, 25 deletions)
--
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]