You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/17 02:50:29 UTC
[incubator-nuttx] 02/02: sched: semaphore: Remove a redundant
critical section in nxsem_tickwait()
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 7758f3dcb1dcf61e9280aaba6cc98668e6c3bc65
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Wed Mar 17 08:33:57 2021 +0900
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 <Ma...@jp.sony.com>
---
sched/semaphore/sem_tickwait.c | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c
index ef90a89..15e7f18 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;
- }
-
- /* We can now restore interrupts */
-
- /* Success exits */
-
-success_with_irqdisabled:
-
- /* Error exits */
+out:
-errout_with_irqdisabled:
- leave_critical_section(flags);
return ret;
}