From 7bb7cd29b2d82c96821aa3849bf30cd6dd842b25 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 12 Nov 2021 18:24:58 -0500 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 | 36 +++++++++++++++++++ 1 file changed, 36 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..0091a21 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,42 @@ rt_object_is_systemobject() 的输入参数 |----------|------------| | object | 对象的句柄 | +### 如何遍历内核对象 + +以遍历所有线程为例: + +```c +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的名字 */ + rt_kprintf("name:%s\n", thread->name); +} +``` + +再以遍历所有互斥量为例: + +```c +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的名字 */ + rt_kprintf("name:%s\n", mutex->parent.parent.name); +} +``` + RT-Thread 内核配置示例 ---------------------- -- Gitee