mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
sem_waitirq.c: coverity HIS_metric_violation: RETURN
Refactor nxsem_wait_irq() to consolidate multiple return statements into a single exit point by inverting the mutex condition check. This improves code maintainability and resolves Coverity HIS_metric_violation defect for better compliance with MISRA HIS standards. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -84,47 +84,45 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|||||||
|
|
||||||
/* Mutex is never interrupted by a signal or canceled */
|
/* Mutex is never interrupted by a signal or canceled */
|
||||||
|
|
||||||
if (mutex && (errcode == EINTR || errcode == ECANCELED))
|
if (!(mutex && (errcode == EINTR || errcode == ECANCELED)))
|
||||||
{
|
{
|
||||||
return;
|
/* Restore the correct priority of all threads that hold references
|
||||||
}
|
* to this semaphore.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Restore the correct priority of all threads that hold references
|
nxsem_canceled(wtcb, sem);
|
||||||
* to this semaphore.
|
|
||||||
*/
|
|
||||||
|
|
||||||
nxsem_canceled(wtcb, sem);
|
/* Remove task from waiting list */
|
||||||
|
|
||||||
/* Remove task from waiting list */
|
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
|
||||||
|
|
||||||
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
|
/* This restores the value to what it was before the previous sem_wait.
|
||||||
|
* This caused the thread to be blocked in the first place.
|
||||||
|
*
|
||||||
|
* For mutexes, the holder is updated by the thread itself
|
||||||
|
* when it exits nxsem_wait
|
||||||
|
*/
|
||||||
|
|
||||||
/* This restores the value to what it was before the previous sem_wait.
|
if (!mutex)
|
||||||
* This caused the thread to be blocked in the first place.
|
{
|
||||||
*
|
atomic_fetch_add(NXSEM_COUNT(sem), 1);
|
||||||
* For mutexes, the holder is updated by the thread itself
|
}
|
||||||
* when it exits nxsem_wait
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!mutex)
|
/* Indicate that the wait is over. */
|
||||||
{
|
|
||||||
atomic_fetch_add(NXSEM_COUNT(sem), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indicate that the wait is over. */
|
wtcb->waitobj = NULL;
|
||||||
|
|
||||||
wtcb->waitobj = NULL;
|
/* Mark the errno value for the thread. */
|
||||||
|
|
||||||
/* Mark the errno value for the thread. */
|
wtcb->errcode = errcode;
|
||||||
|
|
||||||
wtcb->errcode = errcode;
|
/* Add the task to ready-to-run task list and
|
||||||
|
* perform the context switch if one is needed
|
||||||
|
*/
|
||||||
|
|
||||||
/* Add the task to ready-to-run task list and
|
if (nxsched_add_readytorun(wtcb))
|
||||||
* perform the context switch if one is needed
|
{
|
||||||
*/
|
up_switch_context(this_task(), rtcb);
|
||||||
|
}
|
||||||
if (nxsched_add_readytorun(wtcb))
|
|
||||||
{
|
|
||||||
up_switch_context(this_task(), rtcb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user