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 03d9d78adff sched_critmonitor.c: coverity HIS_metric_violation: RETURN
03d9d78adff is described below

commit 03d9d78adffb4e6879d9c048755b7fc96894d854
Author: hujun5 <[email protected]>
AuthorDate: Thu Aug 21 11:37:03 2025 +0800

    sched_critmonitor.c: coverity HIS_metric_violation: RETURN
    
    Reduce multiple return statements and simplify control flow by inverting the
    condition check and moving all critical monitoring operations into a single
    conditional block. This improves code maintainability and addresses the
    Coverity HIS_metric_violation (RETURN) defect.
    
    Signed-off-by: hujun5 <[email protected]>
---
 sched/sched/sched_critmonitor.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c
index 2b2637c1f42..94c944b79c2 100644
--- a/sched/sched/sched_critmonitor.c
+++ b/sched/sched/sched_critmonitor.c
@@ -472,21 +472,19 @@ void nxsched_update_critmon(FAR struct tcb_s *tcb)
   clock_t current = perf_gettime();
   clock_t elapsed = current - tcb->run_start;
 
-  if (tcb->task_state != TSTATE_TASK_RUNNING)
+  if (tcb->task_state == TSTATE_TASK_RUNNING)
     {
-      return;
-    }
-
 #ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
-  clock_t tick = elapsed * CLOCKS_PER_SEC / perf_getfreq();
-  nxsched_process_taskload_ticks(tcb, tick);
+      clock_t tick = elapsed * CLOCKS_PER_SEC / perf_getfreq();
+      nxsched_process_taskload_ticks(tcb, tick);
 #endif
 
-  tcb->run_start = current;
-  tcb->run_time += elapsed;
-  if (elapsed > tcb->run_max)
-    {
-      tcb->run_max = elapsed;
-      CHECK_THREAD(tcb->pid, elapsed);
+      tcb->run_start = current;
+      tcb->run_time += elapsed;
+      if (elapsed > tcb->run_max)
+        {
+          tcb->run_max = elapsed;
+          CHECK_THREAD(tcb->pid, elapsed);
+        }
     }
 }

Reply via email to