You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/01/30 00:59:23 UTC

[nuttx] branch master updated: sched/pthread: set default pthread name to parent's name

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ad0a02182 sched/pthread: set default pthread name to parent's name
2ad0a02182 is described below

commit 2ad0a0218233853ee6055db898b4eaf5a243d5e3
Author: chao an <an...@xiaomi.com>
AuthorDate: Sun Jan 29 16:27:04 2023 +0800

    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 <an...@xiaomi.com>
---
 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 88a87c5ad1..1568bd1863 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[] = "<pthread>";
-#endif
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -95,13 +85,14 @@ static const char g_pthreadname[] = "<pthread>";
  ****************************************************************************/
 
 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);