anchao commented on code in PR #14578:
URL: https://github.com/apache/nuttx/pull/14578#discussion_r1861512296


##########
sched/irq/irq_csection.c:
##########
@@ -440,22 +434,34 @@ void leave_critical_section(irqstate_t flags)
        */
 
       DEBUGASSERT(rtcb->irqcount > 0);
-      if (--rtcb->irqcount <= 0)
-        {
-          /* Note that we have left the critical section */
-
-#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
-          nxsched_critmon_csection(rtcb, false, return_address(0));
-#endif
-#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
-          sched_note_csection(rtcb, false);
-#endif
-        }
+      --rtcb->irqcount;
     }
 
   /* Restore the previous interrupt state. */
 
   up_irq_restore(flags);
 }
 #endif
+
+#if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0 ||\
+    defined(CONFIG_SCHED_INSTRUMENTATION_CSECTION)
+void leave_critical_section(irqstate_t flags)
+{
+  FAR struct tcb_s *rtcb;
+
+  rtcb = this_task();
+  if (rtcb->irqcount == 1 && !up_interrupt_context())
+    {
+#  if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
+      nxsched_critmon_csection(rtcb, false, return_address(0));
+#  endif
+#  ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
+      sched_note_csection(rtcb, false);
+#  endif
+    }

Review Comment:
   ```suggestion
   
     if (!up_interrupt_context())
       {
         rtcb = this_task();
         if (rtcb->irqcount == 1)
           {
   #  if CONFIG_SCHED_CRITMONITOR_MAXTIME_CSECTION >= 0
           nxsched_critmon_csection(rtcb, false, return_address(0));
   #  endif
   #  ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
           sched_note_csection(rtcb, false);
   #  endif
           }
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to