Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */

Expand Down
3 changes: 2 additions & 1 deletion src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion src/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
14 changes: 10 additions & 4 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down