搜索
查看: 1025|回复: 0

[求助] FREERTOS 的列表问题?

[复制链接]

该用户从未签到

48

主题

169

帖子

4

蝴蝶豆

金牌会员

最后登录
2022-3-15
发表于 2018-11-29 17:14:13 | 显示全部楼层 |阅读模式
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
   ListItem_t * const pxIndex = pxList->pxIndex;
/* Insert a new list item into pxList, but rather than sort the list,
makes the new list item the last item to be removed by a call to
listGET_OWNER_OF_NEXT_ENTRY(). */
pxNewListItem->pxNext = pxIndex;
pxNewListItem->pxPrevious = pxIndex->pxPrevious;
pxIndex->pxPrevious->pxNext = pxNewListItem;
pxIndex->pxPrevious = pxNewListItem;
/* Remember which list the item is in. */
pxNewListItem->pvContainer = ( void * ) pxList;
( pxList->uxNumberOfItems )++;
}
pxList->pxIndex 这个指针为啥在插入新变量之后不更新?函数结尾处,它应该指向新添加的变量吧。
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t *pxIterator;
const uint xValueOfInsertion = pxNewListItem->xItemValue;

/* Insert the new list item into the list, sorted in xItemValue order.
If the list already contains a list item with the same item value then the
new list item should be placed after it.  This ensures that TCB's which are
stored in ready lists (all of which have the same xItemValue value) get a
share of the CPU.  However, if the xItemValue is the same as the back marker
the iteration loop below will not end.  Therefore the value is checked
first, and the algorithm slightly modified if necessary. */
if( xValueOfInsertion == 0xFFFFFFFF )
{
  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;
/* Remember which list the item is in.  This allows fast removal of the
item later. */
pxNewListItem->pvContainer = ( void * ) pxList;
( pxList->uxNumberOfItems )++;
}
这个函数中pxNext 指针的值也没更新
uint uxListRemove( ListItem_t * const pxItemToRemove )
{

/* The list item knows which list it is in.  Obtain the list from the list
item. */
  List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;

pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
/* Make sure the index is left pointing to a valid item. */
if( pxList->pxIndex == pxItemToRemove )
{
  pxList->pxIndex = pxItemToRemove->pxPrevious;
}
else
{
  
}
pxItemToRemove->pvContainer = NULL;
( pxList->uxNumberOfItems )--;
return pxList->uxNumberOfItems;
}

只有删除函数中pxNext 指针更新了,这样是不是逻辑不严密呀?
望指点

评分

参与人数 1ST金币 +20 收起 理由
STMCU + 20 活动奖励

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-5-8 06:57 , Processed in 1.161765 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表