From 8ecca52b274960e8cae0e6d27fa065cb6e6e61cb Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Fri, 18 Oct 2024 16:10:28 +0800 Subject: [PATCH] sched/timer: Simplify setitimer implementation. This commit simplified setitmer implementation by eliminating a redundant conditional branch. Signed-off-by: ouyangxiangzhen --- sched/timer/timer_setitimer.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 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); - } + ret = timer_create(CLOCK_REALTIME, NULL, &rtcb->group->itimer); + } - leave_critical_section(flags); + leave_critical_section(flags); - if (ret != OK) - { - return ret; - } + if (ret != OK) + { + return ret; } TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value);