上仙掠夺者 2022-01-04 21:59 采纳率: 33.3%
浏览 6
已结题

FreeRTOS任务ReADD之后会不会破坏双向链表

FreeRTOS 宏定义prvReaddTaskToReadyList,重新添加任务,是否破坏原本的双向链表
涉及到的代码
// 代码位于freeRTOS源码task.c文件的454行附近
#define prvReaddTaskToReadyList( pxTCB )                                                               \
   traceREADDED_TASK_TO_READY_STATE( pxTCB );                                                      \
   taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority );                                             \
   vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )


// 代码位于freeRTOS源码list.c文件的116行附近
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(). 
    插入一个新的节点到pxList中,但是 */
    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 )++;    /* 更新链表节点数 */
}
运行结果及报错内容

实验代码

List_t test;
    ListItem_t item1;
    ListItem_t item2;
    ListItem_t item3;
    ListItem_t item4;
    ListItem_t item5;

    vListInitialise(&test);
    vListInitialiseItem(&item1);
    vListInitialiseItem(&item2);
    vListInitialiseItem(&item3);
    vListInitialiseItem(&item4);
    vListInitialiseItem(&item5);

    item1.xItemValue = 1;
    item2.xItemValue = 2;
    item3.xItemValue = 3;
    item4.xItemValue = 4;
    item5.xItemValue = 5;

    vListInsertEnd(&test, &item1);
    vListInsertEnd(&test, &item2);
    vListInsertEnd(&test, &item3);
    vListInsertEnd(&test, &item4);
    vListInsertEnd(&test, &item5);
    //vListInsertEnd(&test, &item2);  //这一行表示重新添加任务

    for(ListItem_t* item=listGET_HEAD_ENTRY(&test); item->xItemValue<test.xListEnd.xItemValue; item = listGET_NEXT(item)){
        printf("this is item%d\n",item->xItemValue);
    }

this is item1
this is item2
this is item3
this is item4
this is item5

重新添加任务后

this is item1
this is item2
简单的添加前后的示意图

B即为重新添加的任务

img

问题

这样对任务的调度有什么影响,还是说FREERTOS可以把它恢复成正常的双向链表

  • 写回答

1条回答 默认 最新

  • 有问必答小助手 2022-01-06 09:54
    关注

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


    因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    评论

报告相同问题?

问题事件

  • 系统已结题 1月12日
  • 创建了问题 1月4日

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?