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/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ecca52b27 sched/timer: Simplify setitimer implementation.
8ecca52b27 is described below

commit 8ecca52b274960e8cae0e6d27fa065cb6e6e61cb
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Fri Oct 18 16:10:28 2024 +0800

    sched/timer: Simplify setitimer implementation.
    
    This commit simplified setitmer implementation by eliminating a redundant 
conditional branch.
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 sched/timer/timer_setitimer.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/sched/timer/timer_setitimer.c b/sched/timer/timer_setitimer.c
index c8b29fb4c5..e1864bd83e 100644
--- a/sched/timer/timer_setitimer.c
+++ b/sched/timer/timer_setitimer.c
@@ -89,7 +89,7 @@
 int setitimer(int which, FAR const struct itimerval *value,
               FAR struct itimerval *ovalue)
 {
-  FAR struct tcb_s *rtcb = this_task();
+  FAR struct tcb_s *rtcb;
   struct itimerspec spec;
   struct itimerspec ospec;
   irqstate_t flags;
@@ -101,20 +101,20 @@ int setitimer(int which, FAR const struct itimerval 
*value,
       return ERROR;
     }
 
+  rtcb = this_task();
+
+  flags = enter_critical_section();
+
   if (!rtcb->group->itimer)
     {
-      flags = enter_critical_section();
-      if (!rtcb->group->itimer)
-        {
-          ret = timer_create(CLOCK_REALTIME, NULL, &rtcb->group->itimer);
-        }
-
-      leave_critical_section(flags);
-
-      if (ret != OK)
-        {
-          return ret;
-        }
+      ret = timer_create(CLOCK_REALTIME, NULL, &rtcb->group->itimer);
+    }
+
+  leave_critical_section(flags);
+
+  if (ret != OK)
+    {
+      return ret;
     }
 
   TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value);

Reply via email to