note: directly returns the taskname pointer

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-08-11 10:31:03 +08:00 committed by Xiang Xiao
parent 63252af054
commit 4cb2d7dc25
3 changed files with 11 additions and 25 deletions

View File

@ -177,8 +177,7 @@ FAR static struct note_driver_s *
static struct note_taskname_s g_note_taskname;
#endif
#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER) || \
(CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0)
#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER)
static spinlock_t g_note_lock;
#endif
@ -1933,39 +1932,29 @@ void sched_note_filter_tag(FAR struct note_filter_tag_s *oldf,
*
* Input Parameters:
* PID - Task ID
* name - Task name buffer
* this buffer must be greater than CONFIG_TASK_NAME_SIZE + 1
*
* Returned Value:
* Retrun OK if task name can be retrieved, otherwise -ESRCH
*
* Retrun name if task name can be retrieved, otherwise NULL
****************************************************************************/
int note_get_taskname(pid_t pid, FAR char *buffer)
FAR const char *note_get_taskname(pid_t pid)
{
FAR struct note_taskname_info_s *ti;
FAR struct tcb_s *tcb;
irqstate_t irq_mask;
irq_mask = spin_lock_irqsave_wo_note(&g_note_lock);
tcb = nxsched_get_tcb(pid);
if (tcb != NULL)
{
strlcpy(buffer, tcb->name, CONFIG_TASK_NAME_SIZE + 1);
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
return OK;
return tcb->name;
}
ti = note_find_taskname(pid);
if (ti != NULL)
{
strlcpy(buffer, ti->name, CONFIG_TASK_NAME_SIZE + 1);
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
return OK;
return ti->name;
}
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
return -ESRCH;
return NULL;
}
#endif

View File

@ -829,11 +829,10 @@ get_task_context(pid_t pid, FAR struct noteram_dump_context_s *ctx)
#ifdef CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE
{
char taskname[CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE];
int res;
FAR const char *taskname;
res = note_get_taskname(pid, taskname);
if (res == 0)
taskname = note_get_taskname(pid);
if (taskname != NULL)
{
copy_task_name((*tctxp)->name, taskname);
}

View File

@ -145,15 +145,13 @@ int note_initialize(void);
*
* Input Parameters:
* PID - Task ID
* name - Task name buffer
* this buffer must be greater than CONFIG_TASK_NAME_SIZE + 1
*
* Returned Value:
* Retrun OK if task name can be retrieved, otherwise -ESRCH
* Retrun name if task name can be retrieved, otherwise NULL
*
****************************************************************************/
int note_get_taskname(pid_t pid, FAR char *name);
FAR const char *note_get_taskname(pid_t pid);
#endif /* defined(CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE) && \
* CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0