This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ab00bac3154e86b568ef26b176657548f5beaf33
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Nov 3 17:27:45 2026 +0100

    sched/critmon: Fix the build with SCHED_CRITMONITOR_MAXTIME_THREAD -1.
    
    With SCHED_CRITMONITOR_MAXTIME_THREAD set to -1, struct tcb_s has no
    run_start, run_time and run_max.  nxsched_switch_critmon() and
    nxsched_update_critmon() still use them, so the build fails.
    
    Compute the run time slice in nxsched_switch_critmon() only when the
    thread time is monitored.  Build nxsched_update_critmon() only then
    too: its only caller is SCHED_CPULOAD_CRITMONITOR, which depends on
    SCHED_CRITMONITOR_MAXTIME_THREAD >= 0.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 sched/sched/sched.h             | 3 +++
 sched/sched/sched_critmonitor.c | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index a6061a93d04..cc4c4a05d3e 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -446,6 +446,9 @@ void nxsched_switch_context(FAR struct tcb_s *from, FAR 
struct tcb_s *to);
 
 #ifdef CONFIG_SCHED_CRITMONITOR
 void nxsched_switch_critmon(FAR struct tcb_s *from, FAR struct tcb_s *to);
+#endif
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
 void nxsched_update_critmon(FAR struct tcb_s *tcb);
 #endif
 
diff --git a/sched/sched/sched_critmonitor.c b/sched/sched/sched_critmonitor.c
index 49d36fd56e5..3c13e286693 100644
--- a/sched/sched/sched_critmonitor.c
+++ b/sched/sched/sched_critmonitor.c
@@ -371,7 +371,14 @@ void nxsched_critmon_busywait(bool state, FAR void *caller)
 void nxsched_switch_critmon(FAR struct tcb_s *from, FAR struct tcb_s *to)
 {
   clock_t current = perf_gettime();
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
   clock_t elapsed = current - from->run_start;
+#else
+  clock_t elapsed = 0;
+
+  UNUSED(current);
+  UNUSED(elapsed);
+#endif
 
 #ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
   clock_t tick = elapsed * CLK_TCK / perf_getfreq();
@@ -457,6 +464,7 @@ void nxsched_switch_critmon(FAR struct tcb_s *from, FAR 
struct tcb_s *to)
 #endif /* CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION */
 }
 
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
 void nxsched_update_critmon(FAR struct tcb_s *tcb)
 {
   clock_t current = perf_gettime();
@@ -479,3 +487,4 @@ void nxsched_update_critmon(FAR struct tcb_s *tcb)
         }
     }
 }
+#endif

Reply via email to