mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36:28 +08:00
sched: semaphore: Remove a redundant critical section in nxsem_clockwait()
Summary: - This commit removes a redundant critical section in nxsem_clockwait() Impact: - None Testing: - Tested with ostest with the following configurations - maix-bit:smp (QEMU), sim:smp, esp32-devkitc:smp (QEMU) - sabre-6quad:smp (QEMU), spresense:smp - maix-bit:nsh (QEMU), sim:ostest, esp32-devkitc:ostest (QEMU) - sabre-6quad:nsh (QEMU), spresense:wifi Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
committed by
Xiang Xiao
parent
a93d538f3b
commit
65dec5d10a
@@ -91,7 +91,6 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
FAR const struct timespec *abstime)
|
FAR const struct timespec *abstime)
|
||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
irqstate_t flags;
|
|
||||||
sclock_t ticks;
|
sclock_t ticks;
|
||||||
int status;
|
int status;
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
@@ -109,16 +108,11 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* 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);
|
||||||
@@ -126,7 +120,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
{
|
{
|
||||||
/* 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
|
||||||
@@ -136,7 +130,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
|
if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto errout_with_irqdisabled;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert the timespec to clock ticks. We must have interrupts
|
/* Convert the timespec to clock ticks. We must have interrupts
|
||||||
@@ -153,7 +147,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
if (status == OK && ticks <= 0)
|
if (status == OK && ticks <= 0)
|
||||||
{
|
{
|
||||||
ret = -ETIMEDOUT;
|
ret = -ETIMEDOUT;
|
||||||
goto errout_with_irqdisabled;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle any time-related errors */
|
/* Handle any time-related errors */
|
||||||
@@ -161,7 +155,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
if (status != OK)
|
if (status != OK)
|
||||||
{
|
{
|
||||||
ret = -status;
|
ret = -status;
|
||||||
goto errout_with_irqdisabled;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the watchdog */
|
/* Start the watchdog */
|
||||||
@@ -178,11 +172,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|||||||
|
|
||||||
wd_cancel(&rtcb->waitdog);
|
wd_cancel(&rtcb->waitdog);
|
||||||
|
|
||||||
/* We can now restore interrupts and delete the watchdog */
|
out:
|
||||||
|
|
||||||
success_with_irqdisabled:
|
|
||||||
errout_with_irqdisabled:
|
|
||||||
leave_critical_section(flags);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user