Skip to content

Commit

Permalink
[include][src] Add API to get object name and thread name
Browse files Browse the repository at this point in the history
- Added rt_thread_get_name() API
- Added rt_object_get_name() API

Signed-off-by: Fan YANG <fan.yang@hpmicro.com>
  • Loading branch information
Fan YANG committed May 15, 2023
1 parent 8a1260c commit 5978e03
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/rtthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void rt_object_delete(rt_object_t object);
rt_bool_t rt_object_is_systemobject(rt_object_t object);
rt_uint8_t rt_object_get_type(rt_object_t object);
rt_object_t rt_object_find(const char *name, rt_uint8_t type);
const char * rt_object_get_name(rt_object_t object);

#ifdef RT_USING_HEAP
/* custom object */
Expand Down Expand Up @@ -169,6 +170,8 @@ void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void*
#endif
void rt_thread_timeout(void *parameter);

const char *rt_thread_get_name(rt_thread_t thread);

#ifdef RT_USING_SIGNALS
void rt_thread_alloc_sig(rt_thread_t tid);
void rt_thread_free_sig(rt_thread_t tid);
Expand Down
16 changes: 16 additions & 0 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,22 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
return RT_NULL;
}

/**
* @brief This function will return the name of the specified object
* container
*
* @param object is the specified object to be get name
*
* @return the found object name or RT_NULL if there is no this object
* in object container.
*
* @note this function shall not be invoked in interrupt status
*/
const char *rt_object_get_name(rt_object_t object)
{
return (object == RT_NULL) ? RT_NULL : object->name;
}

#ifdef RT_USING_HEAP
/**
* This function will create a custom object
Expand Down
16 changes: 16 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,20 @@ rt_thread_t rt_thread_find(char *name)

RTM_EXPORT(rt_thread_find);

/**
* @brief This function will return the name of the specified thread
*
* @note Please don't invoke this function in interrupt status
*
* @param thread the thread to retrieve thread name
*
* @return If the return value is a valid string, the function is successfully executed
* If the return value is RT_NULL, it means this operation failed
*/
const char * rt_thread_get_name(rt_thread_t thread)
{
return (thread == RT_NULL) ? RT_NULL : rt_object_get_name(&thread->parent);
}
RTM_EXPORT(rt_thread_get_name);

/**@}*/

0 comments on commit 5978e03

Please sign in to comment.