From 7e94dbe102a49b1f8a90c217d39b6a1aff0e3f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=A1=E9=89=B4=E9=9C=86=20Meco?= <920369182@qq.com> Date: Fri, 12 Nov 2021 23:08:14 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E4=BD=95=E9=81=8D=E5=8E=86=E5=86=85?= =?UTF-8?q?=E6=A0=B8=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../programming-manual/basic/basic.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/rt-thread-version/rt-thread-standard/programming-manual/basic/basic.md b/rt-thread-version/rt-thread-standard/programming-manual/basic/basic.md index 8c6d6a1..f175b7d 100644 --- a/rt-thread-version/rt-thread-standard/programming-manual/basic/basic.md +++ b/rt-thread-version/rt-thread-standard/programming-manual/basic/basic.md @@ -545,6 +545,38 @@ rt_object_is_systemobject() 的输入参数 |----------|------------| | object | 对象的句柄 | +#### 如何遍历内核对象 + +```c +//以thread为例 +rt_thread_t thread = RT_NULL; +struct rt_list_node *node = RT_NULL; +struct rt_object_information *information = RT_NULL; + +information = rt_object_get_information(RT_Object_Class_Thread); + +rt_list_for_each(node, &(information->object_list)) +{ + thread = (rt_thread_t)rt_list_entry(node, struct rt_object, list); + /* 你可以对thread开始操作,比如打印所有thread的名字 */ + rt_kprintf("name:%s\n", thread->name); +} + +//再以mutex为例 +rt_mutex_t mutex = RT_NULL; +struct rt_list_node *node = RT_NULL; +struct rt_object_information *information = RT_NULL; + +information = rt_object_get_information(RT_Object_Class_Mutex); + +rt_list_for_each(node, &(information->object_list)) +{ + mutex = (rt_mutex_t)rt_list_entry(node, struct rt_object, list); + /* 你可以对mutex开始操作,比如打印所有mutex的名字 */ + rt_kprintf("name:%s\n", mutex->parent.parent.name); +} +``` + RT-Thread 内核配置示例 ---------------------- -- Gitee