[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 表示已到末尾)

相关推荐
凡人叶枫12 小时前
Effective C++ 条款02:宁可以编译器替换预处理器
java·linux·c语言·开发语言·c++
m0_7381207212 小时前
渗透测试基础——PHP 序列化数据结构与反序列化机制详解
android·服务器·网络·数据结构·安全·php
爱看老照片12 小时前
linux上查看磁盘空间占用情况,清理大文件
linux·清理·大文件·磁盘空间
一个儒雅随和的男子12 小时前
限流算法详细剖析
java·服务器·算法
周杰伦fans12 小时前
AutoCAD2016经典模式不见了-设置回14版本前的经典工作空间
服务器·c语言·前端
鼎讯信通12 小时前
高性能射频信号模块 全方位守护能源设备稳定运行与高效检测
服务器·人工智能·能源
你是个什么橙12 小时前
Linux 远程桌面访问和管理——VNC服务器
linux·运维·服务器
nhfc9912 小时前
whisper.cpp编译
linux·运维·服务器
载数而行52012 小时前
Linux 8 进程(树)相关指令
linux
深圳恒讯12 小时前
越南服务器 ping 值多少?
运维·服务器