In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you how to understand the kernel object operation API in RT-Thread. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Background
The purpose is to learn and be familiar with the RT-Thread operating system.
Start with the simplest object management
Understand the most basic component of the operating system: Object
Kernel object API
The main operation method of kernel object: kernel file: implemented in object.c
Knowledge point
Check out the kernel file: object.c, the main knowledge points found
Verification and testing
If you just look at the kernel code, you might as well knock (copy it).
You can use the simulator to write a few test functions to see the flow of object operation.
Test cases are as follows:
/ * RT-Thread kernel object learning * / # include struct _ obj_type {enum rt_object_class_type type; const char* name;}; / * static object definition * / static struct rt_object_ obj [] = {0} / * for testing, thread object * / 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])) / * static initialization object * / 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, cake!\ n", obj- > name); return } else {rt_object_allocate (RT_Object_Class_Thread, argv [1]); rt_kprintf ("create obj_name=%s\ n", argv [1]);}} / * Printing of objects * / void obj_test_dump (void) {rt_uint8_t index = 0; rt_uint8_t obj_size = 0 Struct rt_object* obj_ pots [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_ pots [index]-> flag, obj_ pots [index]-> type);} rt_kprintf ("+-+\ n");} / * find thread object * / 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]);}} / * static object 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]);}} / * dynamic object 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]);}} / * Export commands * / 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); Learning Summary 1
Found that tshell is a dynamically created thread
Found that tidle is a static thread
Msh / > obj_test_dumpobject init: object size=2 | index | name | flag | type | +-+ | 000 | tshell | 00 | 0x01 | 001 | tidle0 | 00 | 0x81 | +-+ -+ msh / > Summary II
Dynamic object, after creation, memory footprint increases.
Dynamic objects, memory footprint recovery after deletion
Msh / > freetotal memory: 8388580used memory: 5164 / * [5164] original memory size * / 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] memory usage * / maximum allocated memory: 7336msh / > msh / > obj_test _ delete hello obj_name=hellofind obj_name=hellodelete obj_name=hellomsh / > freetotal memory: 8388580used memory: 5164 / * [5304] Memory footprint recovery * / maximum allocated memory: 7336msh / > Summary 3
Statically initialized objects, after detach (excluding object management), the memory footprint remains unchanged.
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 | +-+ -+ | 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 above is the kernel object manipulation API in RT-Thread shared by the editor. How do you understand it? If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.