diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c index 1b38b3faaa4..5f73031b201 100644 --- a/sched/semaphore/sem_waitirq.c +++ b/sched/semaphore/sem_waitirq.c @@ -84,47 +84,45 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode) /* 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 - * to this semaphore. - */ + nxsem_canceled(wtcb, sem); - 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. - * 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 - */ + if (!mutex) + { + atomic_fetch_add(NXSEM_COUNT(sem), 1); + } - if (!mutex) - { - atomic_fetch_add(NXSEM_COUNT(sem), 1); - } + /* Indicate that the wait is over. */ - /* 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 - * perform the context switch if one is needed - */ - - if (nxsched_add_readytorun(wtcb)) - { - up_switch_context(this_task(), rtcb); + if (nxsched_add_readytorun(wtcb)) + { + up_switch_context(this_task(), rtcb); + } } }