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


##########
drivers/note/note_driver.c:
##########
@@ -435,6 +463,92 @@ static inline int note_isenabled_dump(void)
 }
 #endif
 
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_find_taskname
+ *
+ * Description:
+ *   Find task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   Pointer to the task name info
+ *   If the corresponding info doesn't exist in the buffer, NULL is returned.
+ *
+ ****************************************************************************/
+
+static int note_find_taskname(pid_t pid,
+                              FAR struct note_taskname_info_s *info)
+{
+  int n = g_note_taskname.tail;
+  while (n != g_note_taskname.head)
+    {
+      info = (FAR struct note_taskname_info_s *)&g_note_taskname.
+              buffer[n % g_note_taskname.size];
+      n = (n + info->size) % g_note_taskname.size;
+      if (info->pid == pid)
+        {
+          return OK;

Review Comment:
   how your return the task name



##########
drivers/note/note_driver.c:
##########
@@ -435,6 +463,92 @@ static inline int note_isenabled_dump(void)
 }
 #endif
 
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_find_taskname
+ *
+ * Description:
+ *   Find task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   Pointer to the task name info
+ *   If the corresponding info doesn't exist in the buffer, NULL is returned.
+ *
+ ****************************************************************************/
+
+static int note_find_taskname(pid_t pid,
+                              FAR struct note_taskname_info_s *info)
+{
+  int n = g_note_taskname.tail;
+  while (n != g_note_taskname.head)
+    {
+      info = (FAR struct note_taskname_info_s *)&g_note_taskname.
+              buffer[n % g_note_taskname.size];
+      n = (n + info->size) % g_note_taskname.size;

Review Comment:
   move after if statement



##########
drivers/note/note_driver.c:
##########
@@ -435,6 +463,92 @@ static inline int note_isenabled_dump(void)
 }
 #endif
 
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * Name: note_find_taskname
+ *
+ * Description:
+ *   Find task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ *   PID - Task ID
+ *
+ * Returned Value:
+ *   Pointer to the task name info
+ *   If the corresponding info doesn't exist in the buffer, NULL is returned.
+ *
+ ****************************************************************************/
+
+static int note_find_taskname(pid_t pid,
+                              FAR struct note_taskname_info_s *info)
+{
+  int n = g_note_taskname.tail;
+  while (n != g_note_taskname.head)
+    {
+      info = (FAR struct note_taskname_info_s *)&g_note_taskname.
+              buffer[n % g_note_taskname.size];
+      n = (n + info->size) % g_note_taskname.size;
+      if (info->pid == pid)
+        {
+          return OK;
+        }
+    }
+
+  return -ENOENT;
+}
+
+/****************************************************************************
+ * 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
+ *
+ ****************************************************************************/
+
+static void note_record_taskname(pid_t pid, FAR const char *name)
+{
+  char buff[sizeof(struct note_taskname_info_s) + CONFIG_TASK_NAME_SIZE + 1];
+  FAR struct note_taskname_info_s *ti =

Review Comment:
   why not format to the buffer directly



##########
drivers/note/note_driver.c:
##########
@@ -119,6 +121,24 @@ struct note_startalloc_s
 #  define SIZEOF_NOTE_START(n) (sizeof(struct note_start_s))
 #endif
 
+#if CONFIG_TASK_NAME_SIZE > 0
+struct note_taskname_info_s
+{
+  size_t size;
+  pid_t pid;
+  char name[0];
+};
+
+struct note_taskname_s
+{
+  size_t size;
+  size_t space;

Review Comment:
   why add both space and size



##########
drivers/note/noteram_driver.c:
##########
@@ -752,28 +544,16 @@ static int noteram_ioctl(struct file *filep, int cmd, 
unsigned long arg)
 
       case NOTERAM_GETTASKNAME:
         {
-          struct noteram_get_taskname_s *param;
-          const char *taskname;
+          FAR struct noteram_get_taskname_s *param;
 
-        if (arg == 0)
-          {
-            ret = -EINVAL;
-            break;
-          }
-
-          param = (struct noteram_get_taskname_s *)arg;
-          taskname = noteram_get_taskname(param->pid);
-          if (taskname != NULL)
+          if (arg == 0)
             {
-              strlcpy(param->taskname, taskname, CONFIG_TASK_NAME_SIZE + 1);
-              param->taskname[CONFIG_TASK_NAME_SIZE] = '\0';
-              ret = 0;
-            }
-          else
-            {
-              param->taskname[0] = '\0';
-              ret = -ESRCH;
+              ret = -EINVAL;
+              break;
             }
+
+          param = (FAR struct noteram_get_taskname_s *)arg;
+          note_get_taskname(param->pid, param->taskname);

Review Comment:
   ret is still -ENOSYS



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