pkarashchenko commented on code in PR #7900: URL: https://github.com/apache/nuttx/pull/7900#discussion_r1056827303
########## drivers/note/note_driver.c: ########## @@ -435,6 +455,127 @@ static inline int note_isenabled_dump(void) } #endif +#if CONFIG_DRIVER_NOTE_TASKNAME_BUFSIZE > 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 FAR struct note_taskname_info_s *note_find_taskname(pid_t pid) +{ + FAR struct note_taskname_info_s *ti; + int n = g_note_taskname.tail; + + while (n != g_note_taskname.head) + { + 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; + if (n >= CONFIG_DRIVER_NOTE_TASKNAME_BUFSIZE) + { + n -= CONFIG_DRIVER_NOTE_TASKNAME_BUFSIZE; + } + } + + 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 + * + ****************************************************************************/ + +static void note_record_taskname(pid_t pid, FAR const char *name) +{ + FAR struct note_taskname_info_s *ti; + size_t tilen; + size_t namelen; + size_t skiplen; + size_t remain; + + namelen = strlen(name); + DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE); + tilen = sizeof(struct note_taskname_info_s) + namelen; + DEBUGASSERT(tilen <= UCHAR_MAX); + + skiplen = CONFIG_DRIVER_NOTE_TASKNAME_BUFSIZE - g_note_taskname.head; + if (skiplen >= tilen + sizeof(struct note_taskname_info_s)) + { + skiplen = 0; /* Have enough space at the tail - needn't skip */ + } + + if (g_note_taskname.head >= g_note_taskname.tail) + { + remain = CONFIG_DRIVER_NOTE_TASKNAME_BUFSIZE - + (g_note_taskname.head - g_note_taskname.tail); + } + else + { + remain = g_note_taskname.tail - g_note_taskname.head; + } + + while (skiplen + tilen >= remain) + { + /* No enough space, drop the old info */ + + ti = (FAR struct note_taskname_info_s *) + &g_note_taskname.buffer[g_note_taskname.tail]; + g_note_taskname.tail += ti->size; + remain += ti->size; + } + + if (skiplen) + { + /* Fill the skipped region with an invalid info */ + + ti = (FAR struct note_taskname_info_s *) + &g_note_taskname.buffer[g_note_taskname.head]; + ti->size = skiplen; + ti->pid[0] = 0xff; + ti->pid[1] = 0xff; + ti->name[0] = 0; Review Comment: ```suggestion ti->name[0] = '\0'; ``` -- 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