FreeRTOS代码剖析之5:链表管理list.c

链表是操作系统中常用的数据结构,其结构比较简单,因此在剖析freertos的内核时先从这里开始入手。
链表是由众多链表节点组成的,在freertos中,链表节点有两种定义,分别是xlist_item和xmini_list_item。这两种有什么区别呢?可以说,xmini_list_item是xlist_item的浓缩版。看看两者的定义。
struct xlist_item
{
configlist_volatile ticktype_t xitemvalue; /*< the value being listed. in most cases this is used to sort the list in descending order. */
struct xlist_item * configlist_volatile pxnext; /*< pointer to the next listitem_t in the list. */
struct xlist_item * configlist_volatile pxprevious; /*< pointer to the previous listitem_t in the list. */
void * pvowner; /*xlistend ); /*lint !e826 !e740 the mini list structure is used as the list end to save ram. this is checked and valid. */
/* the list end value is the highest possible value in the list to
ensure it remains at the end of the list. */
pxlist->xlistend.xitemvalue = portmax_delay;
/* the list end next and previous pointers point to itself so we know
when the list is empty. */
pxlist->xlistend.pxnext = ( listitem_t * ) &( pxlist->xlistend ); /*lint !e826 !e740 the mini list structure is used as the list end to save ram. this is checked and valid. */
pxlist->xlistend.pxprevious = ( listitem_t * ) &( pxlist->xlistend );/*lint !e826 !e740 the mini list structure is used as the list end to save ram. this is checked and valid. */
pxlist->uxnumberofitems = ( ubasetype_t ) 0u;
}
从整段代码中可以看出,初始化后的链表是一个循环链表,以xlistend为尾。整个链表只有一个节点(就是xlistend)。而头节点则是xlistend的下一个节点。另外,尾节点的节点值为portmax_delay。
感觉再用代码和文字说明会比较吃力,还是上图描述比较好。可以说,整条链表是按以下方式进行管理的。首先是初始化状态,如下图所示:
p指针为前一节点指针,n为下一节点指针。接下来是插入操作。插入节点有两种类型,第一种是添加新节点到尾部。根据代码描述,这种类型的插入结果如下图所示。可以看出整条链表是一条循环链表,用链表中的xlistend来指示链表结尾,并用来给出链表头入口。
上图的添加节点new4是属于第二种节点插入的情况,根据代码描述,是按值的顺序来决定插入位置的,只要遇到链表中的其中一个节点b的值比新节点a的值要大,那么a就插入到b的前面。例如,节点值排序为new2
Eggtronic与益登科技合作 扩大亚太区业务市场
医疗人工智能遭遇的一些发展困境
基于hx711的51单片机电子秤设计
集成Notes和Exchange用户以实现无缝协作
无与伦比的威力与灵活性!赛灵思电源效率解决方案
FreeRTOS代码剖析之5:链表管理list.c
谷歌在今年商业化无人驾驶出租车业务 百度、华为和滴滴遭遇危机
如何选择示波器的带宽、采样率、存储深度、垂直分辨率
OPPOR11什么时候上市最新消息:OPPOR11发布会、发布会形式、发布会明星明日揭晓 ,拍照技术3大汇总
基于HPM6000系列芯片如何使用Flash模拟EEPROM存储参数
Linux系统ELF程序的执行过程
办公空间照明融入互联网文化是种什么体验?
电机能量回收原理
蓝牙耳机哪个好?2021年游戏蓝牙耳机排行榜
上半年全球风险投资额缩水48%至1739亿美元 近四分之一流向AI初创公司
DSl8B20构成的多点温度测量系统的设计
智能穿戴的春天来了?上海物联网及智能穿戴式峰会为你揭秘
爱仕达助推五金行业 实现自动化、智能化转型升级
揭秘日本雷克萨斯九州工厂
6位智能制造领域代表将提哪些议案?