In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what is the organization of kernel object initialization linked list". In daily operation, I believe that many people have doubts about what kernel object initialization linked list organization is. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "what is kernel object initialization linked list organization?" Next, please follow the editor to study!
Background
Recently looking at the source code of the RT-Thread kernel, kernel objects are organized using linked lists.
Inside RT-Thread, there are complete [bi-directional linked list] and [unidirectional linked list] operation API and actual use cases.
Kernel objects, such as threads, timers, devices, etc. derived from the kernel, are managed by linked lists.
Introduction to linked list / * Double List structure * / struct rt_list_node {struct rt_list_node * next; / * *
< point to next node. */ struct rt_list_node *prev; /**< point to prev node. */};typedef struct rt_list_node rt_list_t; /**< Type for lists. */ 链表是一种数据结构,跟其他的结构体类似,初始化后,本身占用内存空间,自身有内存地址。 一般双向链表,内部的成员,是链表本身结构体的指针,注意,指针的指向,初始化后,并没有确定。 RT-Thread 的双向链表,初始化时,内部的指针,指向自己本身的地址,也就是给链表的成员,赋好了初值(指针内容,一般是地址)。 链表使用,节点一般都是【全局结构体变量】,全局静态初始化,或动态内存申请(全局)。 不用全局的链表节点,注意不要链入链表结构,否则节点地址因为【生命周期】结束内存释放了,地址就不对了,就无法管理各个链表的节点了。 双向链表API 这里注要提一下链表节点的插入【次序】,因为遇到了一点小困惑,所以深入的研究了下。 理解:【最新节点】【前一个节点】【最早节点】 链表的头的问题:内核对象使用【对象容器】,全局的,对象初始化后,用了 rt_list_insert_after /* 来自:object.c :rt_object_init */ /* insert object into information object list */ rt_list_insert_after(&(information->Object_list), & (object- > list)
Note that rt_list_insert_after, the insertion position, [is not the end of the linked list insert, but after the first linked list node [first parameter]. ]
That is, if three kernel objects are created, the default sort is as follows:
Not [container head]-- [obj1]-- [obj2]-- [obj2] but: [container head]-- [obj3]-- [obj2]-- [obj1]
If you insert the linked list after the tail, move the list pointer to the tail before executing: rt_list_insert_after.
View kernel objects
In fact, objects such as thread,device are all derived from kernel objects.
RT-Thread provides list_thread, list_device, and so on, to view kernel objects.
Look at the thread initialization [order] and see the last printed thread, which is the first thread to be created.
It is common to traverse each linked list node starting from the [header] of the linked list. As follows: the last node is: mainthread.
In fact, the main thread is the first to be created.
Msh / > list_threadthread pri status sp stack size max used left tick error- persim 16 suspend 0x000001ec 0x0000c000 08% 0x00000003 000sens 28 suspend 0x000000d8 0x00001000 13% 0x00000019 000hws 28 suspend 0x000000d8 0x00000800 10 0x00000032 000dcm_tpo 10 suspend 0x00000090 0x00000800 14% 0x00000004 000dcm_tpo 10 suspend 0x00000090 0x00000800 14% 0x00000002 000dcm_tpo 10 suspend 0x00000090 0x00000800 15 0x00000004 000tshell 20 running 0x000001fc 0x00001000 26% 0x0000000a 000touch 16 suspend 0x00000098 0x00000800 18% 0x00000013 000usbd 8 suspend 0x000000ac 0x00001000 04% 0x00000014 000at_clnt 9 suspend 0x000000c0 0x00000600 12% 0x00000002 000ulog_asy 30 suspend 0x00000084 0x00000c00 09 0x00000006 000mmcsd_de 22 suspend 0x000000a0 0x00000400 48% 0x00000014 000alarmsvc 10 suspend 0x000000a8 0x00000800 27% 0x00000003 000rils 12 suspend 0x000000b0 0x00000800 08% 0x0000001e 000tidle0 31 ready 0x00000058 0x00000800 04% 0x0000001d 000timer 4 suspend 0x00000074 0x00000800 08% 0x00000009 000main 10 suspend 0x00000120 0x00000800 41% 0x00000012 000 / * first created thread Finally print * /
Kernel object initialization linked list [order]:
At this point, the study on "what is the organization of kernel object initialization linked list" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.