sched: semaphore: Remove a redundant critical section in nxsem_tickwait()

Summary:
- This commit removes a redundant critical section in nxsem_tickkwait()

Impact:
- None

Testing:
- Tested with ping with the following configs
- spresense:rndis, spresense:rndis_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa
2021-03-17 08:33:57 +09:00
committed by Xiang Xiao
parent 65dec5d10a
commit 7758f3dcb1
+7 -26
View File
@@ -70,22 +70,16 @@
int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay) int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay)
{ {
FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *rtcb = this_task();
irqstate_t flags;
clock_t elapsed; clock_t elapsed;
int ret; int ret;
DEBUGASSERT(sem != NULL && up_interrupt_context() == false); DEBUGASSERT(sem != NULL && up_interrupt_context() == false);
/* We will disable interrupts until we have completed the semaphore /* NOTE: We do not need a critical section here, because
* wait. We need to do this (as opposed to just disabling pre-emption) * nxsem_wait() and nxsem_timeout() use a critical section
* because there could be interrupt handlers that are asynchronously * in the functions.
* 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.
*/ */
flags = enter_critical_section();
/* Try to take the semaphore without waiting. */ /* Try to take the semaphore without waiting. */
ret = nxsem_trywait(sem); ret = nxsem_trywait(sem);
@@ -93,7 +87,7 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay)
{ {
/* We got it! */ /* We got it! */
goto success_with_irqdisabled; goto out;
} }
/* We will have to wait for the semaphore. Make sure that we were provided /* 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() */ /* Return the errno from nxsem_trywait() */
goto errout_with_irqdisabled; goto out;
} }
/* Adjust the delay for any time since the delay was calculated */ /* 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) if (/* elapsed >= (UINT32_MAX / 2) || */ elapsed >= delay)
{ {
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
goto errout_with_irqdisabled; goto out;
} }
delay -= elapsed; delay -= elapsed;
@@ -130,21 +124,8 @@ int nxsem_tickwait(FAR sem_t *sem, clock_t start, uint32_t delay)
wd_cancel(&rtcb->waitdog); wd_cancel(&rtcb->waitdog);
if (ret < 0) out:
{
goto errout_with_irqdisabled;
}
/* We can now restore interrupts */
/* Success exits */
success_with_irqdisabled:
/* Error exits */
errout_with_irqdisabled:
leave_critical_section(flags);
return ret; return ret;
} }