xiaoxiang781216 commented on code in PR #7900:
URL: https://github.com/apache/nuttx/pull/7900#discussion_r1051404707


##########
drivers/note/note_driver.c:
##########
@@ -1699,3 +1803,52 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s 
*oldf,
 #endif
 
 #endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ *   Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - Task name buffer
+ *   this buffer must be greater than CONFIG_TASK_NAME_SIZE + 1
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_get_taskname(pid_t pid, FAR char *buffer)
+{
+  irqstate_t irq_mask;
+  FAR const char *name = NULL;
+  FAR struct note_taskname_info_s *ti;
+  FAR struct tcb_s *tcb;
+
+  irq_mask = enter_critical_section();
+
+  ti = note_find_taskname(pid);
+  if (ti != NULL)
+    {
+      name = ti->name;
+    }
+  else
+    {
+      tcb = nxsched_get_tcb(pid);
+      if (tcb != NULL)
+        {
+          note_record_taskname(pid, tcb->name);
+          name = tcb->name;
+        }
+    }
+
+  strlcpy(buffer, name, CONFIG_TASK_NAME_SIZE + 1);
+  buffer[CONFIG_TASK_NAME_SIZE] = '\0';

Review Comment:
   remove don't need



##########
drivers/note/note_driver.c:
##########
@@ -1603,6 +1700,13 @@ void sched_note_filter_mode(FAR struct 
note_filter_mode_s *oldm,
       g_note_filter.mode = *newm;
     }
 
+  /* Clear the taskname buffer if note is closed */
+
+  if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE))

Review Comment:
   remove



##########
drivers/note/note_driver.c:
##########
@@ -499,8 +596,8 @@ void sched_note_start(FAR struct tcb_s *tcb)
 
           DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
           strlcpy(note.nsa_name, tcb->name, sizeof(note.nsa_name));
-
           length = SIZEOF_NOTE_START(namelen + 1);
+          note_record_taskname(tcb->pid, tcb->name);

Review Comment:
   move to sched_note_stop



##########
drivers/note/note_driver.c:
##########
@@ -1699,3 +1803,52 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s 
*oldf,
 #endif
 
 #endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ *   Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - Task name buffer
+ *   this buffer must be greater than CONFIG_TASK_NAME_SIZE + 1
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_get_taskname(pid_t pid, FAR char *buffer)
+{
+  irqstate_t irq_mask;
+  FAR const char *name = NULL;
+  FAR struct note_taskname_info_s *ti;
+  FAR struct tcb_s *tcb;
+
+  irq_mask = enter_critical_section();
+
+  ti = note_find_taskname(pid);
+  if (ti != NULL)
+    {
+      name = ti->name;
+    }
+  else
+    {
+      tcb = nxsched_get_tcb(pid);
+      if (tcb != NULL)
+        {
+          note_record_taskname(pid, tcb->name);

Review Comment:
   remove



##########
include/nuttx/note/note_driver.h:
##########
@@ -130,4 +130,25 @@ int note_initialize(void);
 
 #endif /* defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) */
 
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ *   Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - Task name buffer
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_get_taskname(pid_t pid, FAR char *name);

Review Comment:
   void->int, need tell caller the result



##########
drivers/note/note_driver.c:
##########
@@ -1699,3 +1803,52 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s 
*oldf,
 #endif
 
 #endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ *   Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - Task name buffer
+ *   this buffer must be greater than CONFIG_TASK_NAME_SIZE + 1
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_get_taskname(pid_t pid, FAR char *buffer)
+{
+  irqstate_t irq_mask;
+  FAR const char *name = NULL;
+  FAR struct note_taskname_info_s *ti;
+  FAR struct tcb_s *tcb;
+
+  irq_mask = enter_critical_section();
+
+  ti = note_find_taskname(pid);
+  if (ti != NULL)
+    {
+      name = ti->name;
+    }
+  else
+    {
+      tcb = nxsched_get_tcb(pid);
+      if (tcb != NULL)
+        {
+          note_record_taskname(pid, tcb->name);
+          name = tcb->name;
+        }
+    }
+
+  strlcpy(buffer, name, CONFIG_TASK_NAME_SIZE + 1);

Review Comment:
   strcpy is safe here



-- 
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