Skip to content

Commit 41f6f27

Browse files
author
Fan YANG
committed
[include][src] Add API to get object name and thread name
- Added rt_thread_get_name() API - Added rt_object_get_name() API Signed-off-by: Fan Yang <[email protected]>
1 parent 8a1260c commit 41f6f27

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/rtthread.h

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void rt_object_delete(rt_object_t object);
6060
rt_bool_t rt_object_is_systemobject(rt_object_t object);
6161
rt_uint8_t rt_object_get_type(rt_object_t object);
6262
rt_object_t rt_object_find(const char *name, rt_uint8_t type);
63+
const char * rt_object_get_name(rt_object_t object);
6364

6465
#ifdef RT_USING_HEAP
6566
/* custom object */
@@ -169,6 +170,8 @@ void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void*
169170
#endif
170171
void rt_thread_timeout(void *parameter);
171172

173+
const char *rt_thread_get_name(rt_thread_t thread);
174+
172175
#ifdef RT_USING_SIGNALS
173176
void rt_thread_alloc_sig(rt_thread_t tid);
174177
void rt_thread_free_sig(rt_thread_t tid);

src/object.c

+16
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,22 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
635635
return RT_NULL;
636636
}
637637

638+
/**
639+
* @brief This function will return the name of the specified object
640+
* container
641+
*
642+
* @param object is the specified object to be get name
643+
*
644+
* @return the found object name or RT_NULL if there is no this object
645+
* in object container.
646+
*
647+
* @note this function shall not be invoked in interrupt status
648+
*/
649+
const char *rt_object_get_name(rt_object_t object)
650+
{
651+
return (object == RT_NULL) ? RT_NULL : object->name;
652+
}
653+
638654
#ifdef RT_USING_HEAP
639655
/**
640656
* This function will create a custom object

src/thread.c

+16
Original file line numberDiff line numberDiff line change
@@ -1142,4 +1142,20 @@ rt_thread_t rt_thread_find(char *name)
11421142

11431143
RTM_EXPORT(rt_thread_find);
11441144

1145+
/**
1146+
* @brief This function will return the name of the specified thread
1147+
*
1148+
* @note Please don't invoke this function in interrupt status
1149+
*
1150+
* @param thread the thread to retrieve thread name
1151+
*
1152+
* @return If the return value is a valid string, the function is successfully executed
1153+
* If the return value is RT_NULL, it means this operation failed
1154+
*/
1155+
const char * rt_thread_get_name(rt_thread_t thread)
1156+
{
1157+
return (thread == RT_NULL) ? RT_NULL : rt_object_get_name(&thread->parent);
1158+
}
1159+
RTM_EXPORT(rt_thread_get_name);
1160+
11451161
/**@}*/

0 commit comments

Comments
 (0)