RT-Thread中的内核对象操作API怎么理解
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这期内容当中小编将会给大家带来有关RT-Thread中的内核对象操作API怎么理解,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。背景目的还是学习并熟悉RT-Thre
千家信息网最后更新 2025年12月02日RT-Thread中的内核对象操作API怎么理解
这期内容当中小编将会给大家带来有关RT-Thread中的内核对象操作API怎么理解,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
背景
目的还是学习并熟悉RT-Thread 操作系统。
从最简单的对象管理切入
了解操作系统最基本的组成单位:Object
内核对象API
内核对象的主要操作方法:内核文件:object.c中实现
知识点
查看内核文件:object.c,发现的主要的几个知识点
验证与测试
光看内核代码,不如敲一敲(抄一下)。
可以使用模拟器,写几个测试函数,看看对象操作的流程。
测试用例如下:
/* RT-Thread 内核对象学习 */#includestruct _obj_type{ enum rt_object_class_type type; const char* name;};/* 静态的对象定义 */static struct rt_object _obj[] = { 0 };/* 测试用,线程对象 */static const struct _obj_type _obj_tbl[] ={ { RT_Object_Class_Thread, "th_01" }, { RT_Object_Class_Thread, "th_02" }, { RT_Object_Class_Thread, "th_03" }, { RT_Object_Class_Thread, "th_04" }, { RT_Object_Class_Thread, "th_05" },};#define OBJ_TEST_TBL_SIZE (sizeof(_obj_tbl) / sizeof(_obj_tbl[0]))/* 静态初始化对象 */void obj_test_init(void){ rt_uint8_t index = 0; rt_uint8_t obj_size = 0; for (index = 0; index < OBJ_TEST_TBL_SIZE; index++) { rt_object_init(&_obj[index], _obj_tbl[index].type, _obj_tbl[index].name); }}/* 动态创建对象 obj_test_create thread1 */void obj_test_create(uint8_t argc, char** argv){ struct rt_object* obj = RT_NULL; if (argc >= 2) { rt_kprintf(" obj_name=%s\n", argv[1]); } obj = rt_object_find(argv[1], RT_Object_Class_Thread); if (obj != RT_NULL) { rt_kprintf("obj_name=%s, exist!!\n", obj->name); return; } else { rt_object_allocate(RT_Object_Class_Thread, argv[1]); rt_kprintf("create obj_name=%s\n", argv[1]); }}/* 对象的打印 */void obj_test_dump(void){ rt_uint8_t index = 0; rt_uint8_t obj_size = 0; struct rt_object* obj_pointers[OBJ_TEST_TBL_SIZE + 10] = { 0 }; obj_size = rt_object_get_pointers(RT_Object_Class_Thread, obj_pointers, sizeof(obj_pointers)); rt_kprintf("object init : object size=%d\n", obj_size); rt_kprintf("| index | name | flag | type |\n"); rt_kprintf("+-------+--------------+--------+--------+\n"); for (index = 0; index < obj_size; index++) { if (obj_pointers[index] == RT_NULL) { break; } rt_kprintf("| d | s | d | 0xx |\n", index, obj_pointers[index]->name, obj_pointers[index]->flag, obj_pointers[index]->type); } rt_kprintf("+-------+--------------+--------+--------+\n");}/* 查找线程对象 */void obj_test_find(uint8_t argc, char** argv){ struct rt_object* obj = RT_NULL; if (argc >= 2) { rt_kprintf(" obj_name=%s\n", argv[1]); } obj = rt_object_find(argv[1], RT_Object_Class_Thread); if (obj != RT_NULL) { rt_kprintf("find obj_name=%s\n", obj->name); } else { rt_kprintf("not find obj_name=%s\n", argv[1]); }}/* 静态对象 detach */void obj_test_detach(uint8_t argc, char** argv){ struct rt_object* obj = RT_NULL; if (argc >= 2) { rt_kprintf(" obj_name=%s\n", argv[1]); } obj = rt_object_find(argv[1], RT_Object_Class_Thread); if (obj != RT_NULL) { rt_kprintf("find obj_name=%s\n", obj->name); rt_object_detach(obj); rt_kprintf("detach obj_name=%s\n", obj->name); } else { rt_kprintf("not find obj_name=%s\n", argv[1]); }}/* 动态对象 delete */void obj_test_delete(uint8_t argc, char** argv){ struct rt_object* obj = RT_NULL; if (argc >= 2) { rt_kprintf(" obj_name=%s\n", argv[1]); } obj = rt_object_find(argv[1], RT_Object_Class_Thread); if (obj != RT_NULL) { rt_kprintf("find obj_name=%s\n", obj->name); rt_object_delete(obj); rt_kprintf("delete obj_name=%s\n", obj->name); } else { rt_kprintf("not find obj_name=%s\n", argv[1]); }}/* 导出命令 */MSH_CMD_EXPORT(obj_test_init, object init test);MSH_CMD_EXPORT(obj_test_create, obj create test);MSH_CMD_EXPORT(obj_test_dump, object test dump);MSH_CMD_EXPORT(obj_test_find, object test find);MSH_CMD_EXPORT(obj_test_detach, object test detach);MSH_CMD_EXPORT(obj_test_delete, object test del);
学习总结
总结一
发现:tshell 是动态创建的线程
发现:tidle 是静态的线程
msh />obj_test_dumpobject init : object size=2| index | name | flag | type |+-------+--------------+--------+--------+| 000 | tshell | 00 | 0x01 || 001 | tidle0 | 00 | 0x81 |+-------+--------------+--------+--------+msh />
总结二
动态对象,创建后,内存占用增加。
动态对象,删除后,内存占用恢复
msh />freetotal memory: 8388580used memory : 5164 /* 【5164】 内存原有大小 */maximum allocated memory: 7336msh />msh />objobj_test_initobj_test_createobj_test_dumpobj_test_findobj_test_detachobj_test_deletemsh />obj_test_creobj_test_createmsh />obj_test_create hello obj_name=hellocreate obj_name=hellomsh />msh />frefreemsh />freetotal memory: 8388580used memory : 5304 /* 【5304】 内存占用 */maximum allocated memory: 7336msh />msh />obj_test_delete hello obj_name=hellofind obj_name=hellodelete obj_name=hellomsh />freetotal memory: 8388580used memory : 5164 /* 【5304】,内存占用恢复 */maximum allocated memory: 7336msh />
总结三
静态初始化的对象,detach(剔除对象管理)后,内存占用不变。
msh />obj_test_initmsh />obobj_test_initobj_test_createobj_test_dumpobj_test_findobj_test_detachobj_test_deletemsh />obj_test_duobj_test_dumpmsh />obj_test_dumpobject init : object size=7| index | name | flag | type |+-------+--------------+--------+--------+| 000 | th_05 | 00 | 0x81 || 001 | th_04 | 00 | 0x81 || 002 | th_03 | 00 | 0x81 || 003 | th_02 | 00 | 0x81 || 004 | th_01 | 00 | 0x81 || 005 | tshell | 00 | 0x01 || 006 | tidle0 | 00 | 0x81 |+-------+--------------+--------+--------+msh />freetotal memory: 8388580used memory : 5164maximum allocated memory: 7336msh />msh />objobj_test_initobj_test_createobj_test_dumpobj_test_findobj_test_detachobj_test_deletemsh />obj_test_detaobj_test_detachmsh />obj_test_detach th_04 obj_name=th_04find obj_name=th_04detach obj_name=th_04msh />obj_test_duobj_test_dumpmsh />obj_test_dumpobject init : object size=6| index | name | flag | type |+-------+--------------+--------+--------+| 000 | th_05 | 00 | 0x81 || 001 | th_03 | 00 | 0x81 || 002 | th_02 | 00 | 0x81 || 003 | th_01 | 00 | 0x81 || 004 | tshell | 00 | 0x01 || 005 | tidle0 | 00 | 0x81 |+-------+--------------+--------+--------+msh />msh />freetotal memory: 8388580used memory : 5164maximum allocated memory: 7336
上述就是小编为大家分享的RT-Thread中的内核对象操作API怎么理解了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
对象
内核
内存
静态
动态
线程
测试
知识
学习
操作系统
内容
文件
知识点
系统
分析
管理
专业
中小
代码
内容丰富
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
上海直销网络技术销售公司
浙江app软件开发的报价
hct软件开发
数据库能否存储集合
隆基软件开发面试
计算机网络技术是干嘛
浙江台州塑胶模具erp软件开发
再生资源供应链服务软件开发商
5000元数据库电脑
数据库日常备份周期
win服务器如何远程重启
有关现代互联网科技名句
新加坡网络安全特遣队
油管用什么服务器
请写出jdbc连接数据库代骤
写聊天系统用什么数据库比较好
阿里云服务器空间备份容易吗
抖音的服务器内存得要多大
数据库原理宋亚岚
千方百计数据库损坏
南京微链网络技术有限公司
select 数据库测试题
java 获取服务器目录
阿里云服务器空文件夹在哪里
浪潮服务器启动项按多少
现场总线与网络技术
一个服务器能放多个游戏吗
计算机三级网络技术报名费
开源软件开发设计crm
qq西游数据库