diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index ef90a897ed9..15e7f18ce8f 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -70,22 +70,16 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) { FAR struct tcb_s *rtcb = this_task(); - irqstate_t flags; clock_t elapsed; int ret; DEBUGASSERT(sem != NULL && up_interrupt_context() == false); - /* We will disable interrupts until we have completed the semaphore - * wait. We need to do this (as opposed to just disabling pre-emption) - * because there could be interrupt handlers that are asynchronously - * posting semaphores and to prevent race conditions with watchdog - * timeout. This is not too bad because interrupts will be re- - * enabled while we are blocked waiting for the semaphore. + /* NOTE: We do not need a critical section here, because + * nxsem_wait() and nxsem_timeout() use a critical section + * in the functions. */ - flags = enter_critical_section(); - /* Try to take the semaphore without waiting. */ ret = nxsem_trywait(sem); @@ -93,7 +87,7 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) { /* We got it! */ - goto success_with_irqdisabled; + goto out; } /* We will have to wait for the semaphore. Make sure that we were provided @@ -104,7 +98,7 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) { /* Return the errno from nxsem_trywait() */ - goto errout_with_irqdisabled; + goto out; } /* Adjust the delay for any time since the delay was calculated */ @@ -113,7 +107,7 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) if (/* elapsed >= (UINT32_MAX / 2) || */ elapsed >= delay) { ret = -ETIMEDOUT; - goto errout_with_irqdisabled; + goto out; } delay -= elapsed; @@ -130,21 +124,8 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) wd_cancel(&rtcb->waitdog); - if (ret < 0) - { - goto errout_with_irqdisabled; - } +out: - /* We can now restore interrupts */ - - /* Success exits */ - -success_with_irqdisabled: - - /* Error exits */ - -errout_with_irqdisabled: - leave_critical_section(flags); return ret; }