[PATCH 4/5] score: Add _Thread_Set_name()

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


Add configuration option CONFIGURE_MAXIMUM_THREAD_NAME_SIZE.

Update #2858.
---
 cpukit/sapi/include/confdefs.h                | 18 ++++++++++++++++++
 cpukit/score/include/rtems/score/status.h     |  2 ++
 cpukit/score/include/rtems/score/thread.h     |  8 ++++++++
 cpukit/score/include/rtems/score/threadimpl.h |  5 +++++
 cpukit/score/src/threadname.c                 | 20 ++++++++++++++++++++
 5 files changed, 53 insertions(+)

diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index fd5c365..0f249f8 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -3159,6 +3159,10 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     CONFIGURE_HEAP_HANDLER_OVERHEAD \
   )
 
+#ifndef CONFIGURE_MAXIMUM_THREAD_NAME_SIZE
+  #define CONFIGURE_MAXIMUM_THREAD_NAME_SIZE 16
+#endif
+
 #ifdef CONFIGURE_INIT
   typedef union {
     Scheduler_Node Base;
@@ -3192,6 +3196,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     const size_t _Scheduler_Node_size = sizeof( Configuration_Scheduler_node );
   #endif
 
+  const size_t _Thread_Maximum_name_size = CONFIGURE_MAXIMUM_THREAD_NAME_SIZE;
+
   typedef struct {
     Thread_Control Control;
     #if CONFIGURE_MAXIMUM_USER_EXTENSIONS > 0
@@ -3202,6 +3208,9 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     #ifdef RTEMS_POSIX_API
       POSIX_API_Control API_POSIX;
     #endif
+    #if CONFIGURE_MAXIMUM_THREAD_NAME_SIZE > 1
+      char name[ CONFIGURE_MAXIMUM_THREAD_NAME_SIZE ];
+    #endif
     #if !defined(RTEMS_SCHEDSIM) \
       && defined(RTEMS_NEWLIB) \
       && !defined(CONFIGURE_DISABLE_NEWLIB_REENTRANCY)
@@ -3230,6 +3239,15 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
       ),
       offsetof( Configuration_Thread_control, Newlib )
     }
+    #if CONFIGURE_MAXIMUM_THREAD_NAME_SIZE > 1
+      , {
+        offsetof(
+          Configuration_Thread_control,
+          Control.Join_queue.Queue.name
+        ),
+        offsetof( Configuration_Thread_control, name )
+      }
+    #endif
     #ifdef RTEMS_POSIX_API
       , {
         offsetof(
diff --git a/cpukit/score/include/rtems/score/status.h b/cpukit/score/include/rtems/score/status.h
index 6b6f3c5..2695a03 100644
--- a/cpukit/score/include/rtems/score/status.h
+++ b/cpukit/score/include/rtems/score/status.h
@@ -115,6 +115,8 @@ typedef enum {
     STATUS_BUILD( STATUS_CLASSIC_OBJECT_WAS_DELETED, EINVAL ),
   STATUS_RESOURCE_IN_USE =
     STATUS_BUILD( STATUS_CLASSIC_RESOURCE_IN_USE, EBUSY ),
+  STATUS_RESULT_TOO_LARGE =
+    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, ERANGE ),
   STATUS_SUCCESSFUL =
     STATUS_BUILD( STATUS_CLASSIC_SUCCESSFUL, 0 ),
   STATUS_TIMEOUT =
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 13765fc..c114c91 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -907,6 +907,14 @@ extern const size_t _Thread_Control_add_on_count;
  */
 extern const size_t _Thread_Control_size;
 
+/**
+ * @brief Maximum size of a thread name in characters (including the
+ * terminating '\0' character).
+ *
+ * This value is provided via <rtems/confdefs.h>.
+ */
+extern const size_t _Thread_Maximum_name_size;
+
 /**@}*/
 
 #ifdef __cplusplus
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index cb9e8e6..8ddf74e 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -1951,6 +1951,11 @@ RTEMS_INLINE_ROUTINE void _Thread_Remove_timer_and_unblock(
 #endif
 }
 
+Status_Control _Thread_Set_name(
+  Thread_Control *the_thread,
+  const char     *name
+);
+
 size_t _Thread_Get_name(
   const Thread_Control *the_thread,
   char                 *buffer,
diff --git a/cpukit/score/src/threadname.c b/cpukit/score/src/threadname.c
index 6e4ffa4..a4ee3ab 100644
--- a/cpukit/score/src/threadname.c
+++ b/cpukit/score/src/threadname.c
@@ -14,6 +14,26 @@
 
 #include <string.h>
 
+Status_Control _Thread_Set_name(
+  Thread_Control *the_thread,
+  const char     *name
+)
+{
+  size_t length;
+
+  length = strlcpy(
+    the_thread->Join_queue.Queue.name,
+    name,
+    _Thread_Maximum_name_size
+  );
+
+  if ( length >= _Thread_Maximum_name_size ) {
+    return STATUS_RESULT_TOO_LARGE;
+  }
+
+  return STATUS_SUCCESSFUL;
+}
+
 size_t _Thread_Get_name(
   const Thread_Control *the_thread,
   char                 *buffer,
-- 
1.8.4.5




More information about the devel mailing list