mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 13:18:50 +08:00
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:
parent
65dec5d10a
commit
7758f3dcb1
1 changed files with 7 additions and 26 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue