Gary-Hobson commented on code in PR #7900:
URL: https://github.com/apache/nuttx/pull/7900#discussion_r1050897970


##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ 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_record_taskname
+ *
+ * Description:
+ *   Record the task name info of the specified task
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - task name
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)

Review Comment:
   done



##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ 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_record_taskname
+ *
+ * Description:
+ *   Record the task name info of the specified task
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - task name
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)
+{
+  FAR struct note_taskname_info_s *ti;
+  size_t tilen;
+  size_t namelen;
+
+  namelen = strlen(name);
+  DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
+  tilen = sizeof(struct note_taskname_info_s) + namelen;
+  DEBUGASSERT(tilen <= UCHAR_MAX);
+
+  if (g_note_taskname.buffer_used + tilen >
+      CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE)
+    {
+      /* No space in the buffer - ignored */
+
+      return;
+    }
+
+  ti = (FAR struct note_taskname_info_s *)
+        &g_note_taskname.buffer[g_note_taskname.buffer_used];
+  ti->size = tilen;
+  ti->pid[0] = pid & 0xff;
+  ti->pid[1] = (pid >> 8) & 0xff;
+  strlcpy(ti->name, name, namelen + 1);
+  g_note_taskname.buffer_used += tilen;
+}
+
+/****************************************************************************
+ * Name: note_remove_taskname
+ *
+ * Description:
+ *   Remove the task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_remove_taskname(pid_t pid)

Review Comment:
   done



##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ 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_record_taskname
+ *
+ * Description:
+ *   Record the task name info of the specified task
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *   name - task name
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)
+{
+  FAR struct note_taskname_info_s *ti;
+  size_t tilen;
+  size_t namelen;
+
+  namelen = strlen(name);
+  DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
+  tilen = sizeof(struct note_taskname_info_s) + namelen;
+  DEBUGASSERT(tilen <= UCHAR_MAX);
+
+  if (g_note_taskname.buffer_used + tilen >
+      CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE)
+    {
+      /* No space in the buffer - ignored */
+
+      return;
+    }
+
+  ti = (FAR struct note_taskname_info_s *)
+        &g_note_taskname.buffer[g_note_taskname.buffer_used];
+  ti->size = tilen;
+  ti->pid[0] = pid & 0xff;
+  ti->pid[1] = (pid >> 8) & 0xff;
+  strlcpy(ti->name, name, namelen + 1);
+  g_note_taskname.buffer_used += tilen;
+}
+
+/****************************************************************************
+ * Name: note_remove_taskname
+ *
+ * Description:
+ *   Remove the task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_remove_taskname(pid_t pid)
+{
+  FAR struct note_taskname_info_s *ti;
+  size_t tilen;
+  FAR char *src;
+  int sindex;
+
+  ti = note_find_taskname(pid);
+  if (ti == NULL)
+    {
+      return;
+    }
+
+  tilen = ti->size;
+  src = (FAR char *)ti + tilen;
+  sindex = src - g_note_taskname.buffer;
+
+  memcpy(ti, src, g_note_taskname.buffer_used - sindex);
+  g_note_taskname.buffer_used -= tilen;
+}
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ *   Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   Pointer to the task name string
+ *   If the corresponding name doesn't exist in the buffer, NULL is returned.
+ *
+ ****************************************************************************/
+
+FAR const char *note_get_taskname(pid_t pid)
+{
+  irqstate_t irq_mask;
+  FAR const char *ret = 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)
+    {
+      ret = ti->name;
+    }
+  else
+    {
+      tcb = nxsched_get_tcb(pid);
+      if (tcb != NULL)
+        {
+          note_record_taskname(pid, tcb->name);
+          ret = tcb->name;
+        }
+    }
+
+  leave_critical_section(irq_mask);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: note_clear_taskname
+ *
+ * Description:
+ *   Reset the buffer of note_taskname_s
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void note_clear_taskname(void)

Review Comment:
   done



##########
drivers/note/noteram_driver.c:
##########
@@ -306,7 +124,7 @@ static void noteram_buffer_clear(void)
     }
 
 #if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0
-  g_noteram_taskname.buffer_used = 0;
+  note_clear_taskname();

Review Comment:
   done



##########
drivers/note/noteram_driver.c:
##########
@@ -442,7 +260,7 @@ static void noteram_remove(void)
       nc_pid[1] = g_noteram_info.ni_buffer[noteram_next(tail, 4)];
 #endif
 
-      noteram_remove_taskname(nc_pid[0] + (nc_pid[1] << 8));
+      note_remove_taskname(nc_pid[0] + (nc_pid[1] << 8));

Review Comment:
   done



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