From 2ad0a0218233853ee6055db898b4eaf5a243d5e3 Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 29 Jan 2023 16:27:04 +0800 Subject: [PATCH] sched/pthread: set default pthread name to parent's name Align ps behavior with linux: linux: $ ps -e -T | grep hello 3758130 3758130 pts/10 00:00:00 hello 3758130 3758131 pts/10 00:00:00 hello nuttx: nsh> ps PID GROUP PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK COMMAND ... 4 4 100 FIFO Task --- Waiting Signal 00000000 067504 hello 5 4 100 FIFO pthread --- Waiting Signal 00000000 067536 hello 0x561cef0dfc53 0x1 Signed-off-by: chao an --- sched/pthread/pthread_create.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 88a87c5ad1c..1568bd1863b 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -58,16 +58,6 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if CONFIG_TASK_NAME_SIZE > 0 -/* This is the name for name-less pthreads */ - -static const char g_pthreadname[] = ""; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -95,13 +85,14 @@ static const char g_pthreadname[] = ""; ****************************************************************************/ static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb, + FAR struct tcb_s *parent, pthread_trampoline_t trampoline, pthread_addr_t arg) { #if CONFIG_TASK_NAME_SIZE > 0 /* Copy the pthread name into the TCB */ - strncpy(ptcb->cmn.name, g_pthreadname, CONFIG_TASK_NAME_SIZE); + strncpy(ptcb->cmn.name, parent->name, CONFIG_TASK_NAME_SIZE); ptcb->cmn.name[CONFIG_TASK_NAME_SIZE] = '\0'; #endif /* CONFIG_TASK_NAME_SIZE */ @@ -404,11 +395,14 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, } #endif + parent = this_task(); + DEBUGASSERT(parent != NULL); + /* Configure the TCB for a pthread receiving on parameter * passed by value */ - pthread_tcb_setup(ptcb, trampoline, arg); + pthread_tcb_setup(ptcb, parent, trampoline, arg); /* Join the parent's task group */ @@ -473,9 +467,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, * so it has the same priority as the parent thread. */ - parent = this_task(); - DEBUGASSERT(parent != NULL); - if (ptcb->cmn.sched_priority < parent->sched_priority) { ret = nxsched_set_priority(&ptcb->cmn, parent->sched_priority);