总体结构:
列表结构体里存在两种列表项,列表项的内容在list.h中定义(主要为指针、数量、索引),其相关操作函数有:初始化、插入、删除等
1、列表:
typedef struct xLIST
{
listFIRST_LIST_INTEGRITY_CHECK_VALUE 检查列表的完整性
configLIST_VOLATILE UBaseType_t uxNumberOfItems; 记录列表项的数量
ListItem_t * configLIST_VOLATILE pxIndex; 记录当前列表项的索引号,遍历
MiniListItem_t xListEnd; 表示列表的结束
listSECOND_LIST_INTEGRITY_CHECK_VALUE 检查列表的完整性
} List_t;
2、列表里存在两种列表项:
2.1列表项
struct xLIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE 检查列表的完整性,不用管
configLIST_VOLATILE TickType_t xItemValue; 列表项的值
struct xLIST_ITEM * configLIST_VOLATILE pxNext; 指向下一个列表项
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; 指向前一个列表项
void * pvOwner; 记录列表项归谁拥有,指向任务控制块
void * configLIST_VOLATILE pvContainer; 记录列表项归哪一个列表,指向就绪列表
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE 检查列表的完整性,不用管
};
typedef struct xLIST_ITEM ListItem_t;
2.2另一种是mini列表项:
struct xMINI_LIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE 检查列表的完整性,不用管
configLIST_VOLATILE TickType_t xItemValue;
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
};
typedef struct xMINI_LIST_ITEM MiniListItem_t;
3、列表初始化:
void vListInitialise( List_t * const pxList )
{
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); 说明当前只有一个列表项
pxList->xListEnd.xItemValue = portMAX_DELAY;
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd );
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
}
4、列表项初始化:
void vListInitialiseItem( ListItem_t * const pxItem )
{
pxItem->pvContainer = NULL;
//用于列表项完整性的检查,不用管
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
}
5、列表项插入:
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t *pxIterator;
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
listTEST_LIST_INTEGRITY( pxList );
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
//判断位置
if( xValueOfInsertion == portMAX_DELAY )
{
pxIterator = pxList->xListEnd.pxPrevious;//获取列表项的位置
}
else
{
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
{
/* There is nothing to do here, just iterating to the wanted
insertion position. */
}
}
//插入
pxNewListItem->pxNext = pxIterator->pxNext;
pxNewListItem->pxNext->pxPrevious = pxNewListItem;
pxNewListItem->pxPrevious = pxIterator;
pxIterator->pxNext = pxNewListItem;
//插入后,记录列表项属于哪一个列表
pxNewListItem->pvContainer = ( void * ) pxList;
//列表项数目+1
( pxList->uxNumberOfItems )++;
}
6、列表项末尾插入函数:
插入流程:~ —— ~
7、列表项删除:
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
mtCOVERAGE_TEST_DELAY();
if( pxList->pxIndex == pxItemToRemove )
{
pxList->pxIndex = pxItemToRemove->pxPrevious;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
pxItemToRemove->pvContainer = NULL;
( pxList->uxNumberOfItems )--;
return pxList->uxNumberOfItems;
}