xiaoxiang781216 commented on code in PR #7900: URL: https://github.com/apache/nuttx/pull/7900#discussion_r1051325410
########## drivers/note/noteram_driver.c: ########## @@ -113,170 +95,6 @@ static volatile spinlock_t g_noteram_lock; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: noteram_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. - * - ****************************************************************************/ - -#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0 -static FAR struct noteram_taskname_info_s *noteram_find_taskname(pid_t pid) -{ - int n; - FAR struct noteram_taskname_info_s *ti; - - for (n = 0; n < g_noteram_taskname.buffer_used; ) - { - ti = (FAR struct noteram_taskname_info_s *) - &g_noteram_taskname.buffer[n]; - if (ti->pid[0] + (ti->pid[1] << 8) == pid) - { - return ti; - } - - n += ti->size; - } - - return NULL; -} -#endif - -/**************************************************************************** - * Name: noteram_record_taskname - * - * Description: - * Record the task name info of the specified task - * - * Input Parameters: - * PID - Task ID - * name - task name - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0 -static void noteram_record_taskname(pid_t pid, const char *name) -{ - FAR struct noteram_taskname_info_s *ti; - size_t tilen; - size_t namelen; - - namelen = strlen(name); - DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE); - tilen = sizeof(struct noteram_taskname_info_s) + namelen; - DEBUGASSERT(tilen <= UCHAR_MAX); - - if (g_noteram_taskname.buffer_used + tilen > - CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE) - { - /* No space in the buffer - ignored */ - - return; - } - - ti = (FAR struct noteram_taskname_info_s *) - &g_noteram_taskname.buffer[g_noteram_taskname.buffer_used]; - ti->size = tilen; - ti->pid[0] = pid & 0xff; - ti->pid[1] = (pid >> 8) & 0xff; - strlcpy(ti->name, name, namelen + 1); - g_noteram_taskname.buffer_used += tilen; -} -#endif - -/**************************************************************************** - * Name: noteram_remove_taskname - * - * Description: - * Remove the task name info corresponding to the specified PID - * - * Input Parameters: - * PID - Task ID - * - * Returned Value: - * None - * - ****************************************************************************/ - -#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0 -static void noteram_remove_taskname(pid_t pid) Review Comment: need keep this function and call it in sched_note_stop ########## include/nuttx/note/note_driver.h: ########## @@ -62,4 +62,74 @@ int note_initialize(void); #endif /* defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) */ +#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0 + +/**************************************************************************** + * 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. + * + ****************************************************************************/ + +const char *note_get_taskname(pid_t pid); Review Comment: ```suggestion int note_get_taskname(pid_t pid, FAR char *name); ``` let's copy the internal buffer instead return raw pointer to avoid the race condition ########## drivers/note/note_driver.c: ########## @@ -380,6 +399,84 @@ static inline int note_isenabled_dump(void) } #endif +/**************************************************************************** + * 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 FAR struct note_taskname_info_s *note_find_taskname(pid_t pid) +{ + int n; + FAR struct note_taskname_info_s *ti; + + for (n = 0; n < g_note_taskname.buffer_used; ) + { + ti = (FAR struct note_taskname_info_s *) + &g_note_taskname.buffer[n]; + if (ti->pid[0] + (ti->pid[1] << 8) == pid) + { + return ti; + } + + n += ti->size; + } + + return NULL; +} + +/**************************************************************************** + * 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) Review Comment: need overwrite the old info ########## include/nuttx/note/note_driver.h: ########## @@ -62,4 +62,74 @@ int note_initialize(void); #endif /* defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) */ +#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0 + +/**************************************************************************** + * 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. + * + ****************************************************************************/ + +const char *note_get_taskname(pid_t pid); Review Comment: not fix ########## drivers/note/noteram_driver.c: ########## @@ -745,7 +563,7 @@ static int noteram_ioctl(struct file *filep, int cmd, unsigned long arg) } param = (struct noteram_get_taskname_s *)arg; Review Comment: not fix yet ########## drivers/note/note_driver.c: ########## @@ -380,6 +399,84 @@ static inline int note_isenabled_dump(void) } #endif +/**************************************************************************** + * 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 FAR struct note_taskname_info_s *note_find_taskname(pid_t pid) +{ + int n; + FAR struct note_taskname_info_s *ti; + + for (n = 0; n < g_note_taskname.buffer_used; ) + { + ti = (FAR struct note_taskname_info_s *) + &g_note_taskname.buffer[n]; + if (ti->pid[0] + (ti->pid[1] << 8) == pid) + { + return ti; + } + + n += ti->size; + } + + return NULL; +} + +/**************************************************************************** + * 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: add static -- 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