[PATCH 3/5] score: Add and use _Thread_Get_name()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Jan 12 14:51:23 UTC 2017


Update #2858.
---
 cpukit/libmisc/cpuuse/cpuusagereport.c        |  4 +--
 cpukit/libmisc/monitor/mon-task.c             |  8 +++++-
 cpukit/libmisc/monitor/monitor.h              |  1 +
 cpukit/score/Makefile.am                      |  1 +
 cpukit/score/include/rtems/score/threadimpl.h |  8 +++++-
 cpukit/score/src/threadname.c                 | 37 +++++++++++++++++++++++++++
 6 files changed, 55 insertions(+), 4 deletions(-)
 create mode 100644 cpukit/score/src/threadname.c

diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index 1049296..2a01a8a 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -40,7 +40,7 @@ typedef struct {
 static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
 {
   cpu_usage_context *ctx;
-  char               name[ 13 ];
+  char               name[ 38 ];
   uint32_t           ival;
   uint32_t           fval;
   Timestamp_Control  uptime;
@@ -49,7 +49,7 @@ static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
   uint32_t           nanoseconds;
 
   ctx = arg;
-  rtems_object_get_name( the_thread->Object.id, sizeof( name ), name );
+  _Thread_Get_name( the_thread, name, sizeof( name ) );
 
   _Thread_Get_CPU_time_used( the_thread, &used );
   _TOD_Get_uptime( &uptime );
diff --git a/cpukit/libmisc/monitor/mon-task.c b/cpukit/libmisc/monitor/mon-task.c
index fadf51d..5e948c1 100644
--- a/cpukit/libmisc/monitor/mon-task.c
+++ b/cpukit/libmisc/monitor/mon-task.c
@@ -47,6 +47,12 @@ rtems_monitor_task_canonical(
 
     api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];
 
+    _Thread_Get_name(
+      rtems_thread,
+      canonical_task->name_string,
+      sizeof( canonical_task->name_string )
+    );
+
     rtems_monitor_task_wait_info( canonical_task, rtems_thread );
 
     canonical_task->entry = rtems_thread->Start.Entry;
@@ -97,7 +103,7 @@ rtems_monitor_task_dump(
 
     length += rtems_monitor_dump_id(monitor_task->id);
     length += rtems_monitor_pad(11, length);
-    length += rtems_monitor_dump_name(monitor_task->id);
+    length += fprintf(stdout, "%s", monitor_task->name_string);
     length += rtems_monitor_pad(21, length);
     length += rtems_monitor_dump_decimal(monitor_task->cpu);
     length += rtems_monitor_pad(26, length);
diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h
index e2575cc..a111364 100644
--- a/cpukit/libmisc/monitor/monitor.h
+++ b/cpukit/libmisc/monitor/monitor.h
@@ -95,6 +95,7 @@ typedef struct {
     rtems_id                   id;
     rtems_name                 name;
   /* end of common portion */
+    char                       name_string[10];
     Thread_Entry_information   entry;
     void                      *stack;
     uint32_t                   stack_size;
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 9b376c3..953f1eb 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -299,6 +299,7 @@ libscore_a_SOURCES += src/threadentryadaptorpointer.c
 libscore_a_SOURCES += src/threadgetcputimeused.c
 libscore_a_SOURCES += src/threadglobalconstruction.c
 libscore_a_SOURCES += src/threaditerate.c
+libscore_a_SOURCES += src/threadname.c
 libscore_a_SOURCES += src/threadscheduler.c
 libscore_a_SOURCES += src/threadtimeout.c
 libscore_a_SOURCES += src/threadwaitgetid.c
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index f131bbd..cb9e8e6 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -11,7 +11,7 @@
  *  COPYRIGHT (c) 1989-2008.
  *  On-Line Applications Research Corporation (OAR).
  *
- *  Copyright (c) 2014, 2016 embedded brains GmbH.
+ *  Copyright (c) 2014, 2017 embedded brains GmbH.
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
@@ -1951,6 +1951,12 @@ RTEMS_INLINE_ROUTINE void _Thread_Remove_timer_and_unblock(
 #endif
 }
 
+size_t _Thread_Get_name(
+  const Thread_Control *the_thread,
+  char                 *buffer,
+  size_t                buffer_size
+);
+
 /** @}*/
 
 #ifdef __cplusplus
diff --git a/cpukit/score/src/threadname.c b/cpukit/score/src/threadname.c
new file mode 100644
index 0000000..6e4ffa4
--- /dev/null
+++ b/cpukit/score/src/threadname.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/score/threadimpl.h>
+
+#include <string.h>
+
+size_t _Thread_Get_name(
+  const Thread_Control *the_thread,
+  char                 *buffer,
+  size_t                buffer_size
+)
+{
+  const char *name;
+
+  name = the_thread->Join_queue.Queue.name;
+
+  if ( name != NULL && name[ 0 ] != '\0' ) {
+    return strlcpy( buffer, name, buffer_size );
+  } else {
+    return _Objects_Name_to_string(
+      the_thread->Object.name,
+      false,
+      buffer,
+      buffer_size
+    );
+  }
+}
-- 
1.8.4.5




More information about the devel mailing list