[freeRTOS源码阅读]list.c/h

cpp 复制代码
/*
 * Definition of the type of queue used by the scheduler.
 */
typedef struct xLIST
{
	listFIRST_LIST_INTEGRITY_CHECK_VALUE				/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
	volatile UBaseType_t uxNumberOfItems;
	ListItem_t * configLIST_VOLATILE pxIndex;			/*< Used to walk through the list.  Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */
	MiniListItem_t xListEnd;							/*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
	listSECOND_LIST_INTEGRITY_CHECK_VALUE				/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
} List_t;

void vListInitialise( List_t * const pxList )

cpp 复制代码
void vListInitialise( List_t * const pxList )
{
    /* The list structure contains a list item which is used to mark the
    end of the list.  To initialise the list the list end is inserted
    as the only list entry. */
    /*遍历"游标"*/
    pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd );           /*lint !e826 !e740 !e9087 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 !e9087 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 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */

    pxList->uxNumberOfItems = ( UBaseType_t ) 0U;

    /* Write known values into the list if
    configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
    listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
    listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
}

FreeRTOS 的列表实现是环形双向链表 ,但通过一个特殊的"结束标记"(xListEnd)作为哨兵节点来简化边界处理:

  • 插入、删除操作无需特殊处理头尾边界条件。(循环的原因)

  • 遍历时以 pxIndex 为起点,经过 xListEnd 作为终止判断(比如 pxIndex->pxNext == &pxList->xListEnd 表示已到末尾)

相关推荐
tudoSearcher4 小时前
服务器蓝屏了远程连不上?工业级IP KVM的硬件级抢救实战
运维·服务器·tcp/ip
睡一觉就好了。5 小时前
Linux基础指令(二)
linux
海市公约5 小时前
基于Linux的CentOS 7 下载安装 MySQL 8的全教程
linux·mysql·centos·环境搭建
星间都市山脉5 小时前
Windows 环境 Android 系统 APK 签名操作文档
android·windows
WangLanguager5 小时前
Unix 命令 rm详细介绍
linux·服务器·unix
樱桃花下的小猫5 小时前
Rust 服务器存档管理 & 地图配置指南
服务器·rust·云鸢互联·零门槛一键开服·腐蚀rust服务器·腐蚀rust稳定低延迟联机·腐蚀rust服务器一键开服
鱼听禅5 小时前
CentOS Stream 10系统配置戴尔R730风扇速度
linux·运维·centos
IMPYLH5 小时前
Linux 的 unlink 命令
linux·运维·服务器·bash
vortex55 小时前
Shellinabox 使用指南:基于 Web 的终端模拟器
linux·前端·web ssh