diff --git a/include/rtdef.h b/include/rtdef.h index 8638bc3d13..593bd856b3 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -46,6 +46,7 @@ * 2022-06-29 Meco Man add RT_USING_LIBC and standard libc headers * 2022-08-16 Meco Man change version number to v5.0.0 * 2022-09-12 Meco Man define rt_ssize_t + * 2022-12-20 Meco Man add const name for rt_object */ #ifndef __RT_DEF_H__ @@ -412,21 +413,25 @@ typedef struct rt_slist_node rt_slist_t; /**< Type for single lis */ struct rt_object { - char name[RT_NAME_MAX]; /**< name of kernel object */ - rt_uint8_t type; /**< type of kernel object */ - rt_uint8_t flag; /**< flag of kernel object */ +#if RT_NAME_MAX > 0 + char name[RT_NAME_MAX]; /**< dynamic name of kernel object */ +#else + const char *name; /**< static name of kernel object */ +#endif /* RT_NAME_MAX > 0 */ + rt_uint8_t type; /**< type of kernel object */ + rt_uint8_t flag; /**< flag of kernel object */ #ifdef RT_USING_MODULE - void *module_id; /**< id of application module */ + void * module_id; /**< id of application module */ #endif /* RT_USING_MODULE */ #ifdef RT_USING_SMART - int lwp_ref_count; /**< ref count for lwp */ + int lwp_ref_count; /**< ref count for lwp */ #endif /* RT_USING_SMART */ - rt_list_t list; /**< list node of kernel object */ + rt_list_t list; /**< list node of kernel object */ }; -typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */ +typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */ /** * The object type can be one of the follows with specific @@ -725,7 +730,11 @@ struct rt_user_context struct rt_thread { /* rt object */ - char name[RT_NAME_MAX]; /**< the name of thread */ +#if RT_NAME_MAX > 0 + char name[RT_NAME_MAX]; /**< dynamic name of kernel object */ +#else + const char *name; /**< static name of kernel object */ +#endif /* RT_NAME_MAX > 0 */ rt_uint8_t type; /**< type of object */ rt_uint8_t flags; /**< thread's flags */ diff --git a/src/Kconfig b/src/Kconfig index 88d6c970a0..0a583b407f 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -3,11 +3,12 @@ menu "RT-Thread Kernel" config RT_NAME_MAX int "The maximal size of kernel object name" - range 2 32 + range 0 64 default 8 help Each kernel object, such as thread, timer, semaphore etc, has a name, the RT_NAME_MAX is the maximal size of this object name. + If RT_NAME_MAX sets as 0, the name will be const. config RT_USING_ARCH_DATA_TYPE bool "Use the data types defined in ARCH_CPU" diff --git a/src/idle.c b/src/idle.c index 214a6b2ad2..8b0a49c7f9 100644 --- a/src/idle.c +++ b/src/idle.c @@ -306,13 +306,21 @@ static void rt_thread_system_entry(void *parameter) void rt_thread_idle_init(void) { rt_ubase_t i; +#if RT_NAME_MAX > 0 char idle_thread_name[RT_NAME_MAX]; +#endif /* RT_NAME_MAX > 0 */ for (i = 0; i < _CPUS_NR; i++) { - rt_sprintf(idle_thread_name, "tidle%d", i); +#if RT_NAME_MAX > 0 + rt_snprintf(idle_thread_name, RT_NAME_MAX, "tidle%d", i); +#endif /* RT_NAME_MAX > 0 */ rt_thread_init(&idle_thread[i], +#if RT_NAME_MAX > 0 idle_thread_name, +#else + "tidle", +#endif /* RT_NAME_MAX > 0 */ idle_thread_entry, RT_NULL, &idle_thread_stack[i][0], diff --git a/src/object.c b/src/object.c index 354703b713..b7ccf23725 100644 --- a/src/object.c +++ b/src/object.c @@ -387,8 +387,11 @@ void rt_object_init(struct rt_object *object, /* initialize object's parameters */ /* set object type to static */ object->type = type | RT_Object_Class_Static; - /* copy name */ - rt_strncpy(object->name, name, RT_NAME_MAX); +#if RT_NAME_MAX > 0 + rt_strncpy(object->name, name, RT_NAME_MAX); /* copy name */ +#else + object->name = name; +#endif /* RT_NAME_MAX > 0 */ RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object)); @@ -483,8 +486,11 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) /* set object flag */ object->flag = 0; - /* copy name */ - rt_strncpy(object->name, name, RT_NAME_MAX); +#if RT_NAME_MAX > 0 + rt_strncpy(object->name, name, RT_NAME_MAX); /* copy name */ +#else + object->name = name; +#endif /* RT_NAME_MAX > 0 */ RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));