FreeRTOS 源码注释(prvAddTaskToReadyQueue)

来源:互联网 发布:苹果软件下载排行 编辑:程序博客网 时间:2024/05/16 11:39

/* 将 TCB 插入到对应的就绪链表中,如果对应优先级的链表已经有元素了,就插在其后面 */  

/* 被多个函数调用 */


#define prvAddTaskToReadyQueue( pxTCB )                                                            \
    if( ( pxTCB )->uxPriority > uxTopReadyPriority )                \
    {                                                                \
        uxTopReadyPriority = ( pxTCB )->uxPriority;                    \
    }                                                                \
    vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )

void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )
{
volatile xListItem * 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
    pvListGetOwnerOfNextEntry.  This means it has to be the item pointed to by
    the pxIndex member. */
    pxIndex = pxList->pxIndex;

    pxNewListItem->pxNext = pxIndex->pxNext;
    pxNewListItem->pxPrevious = pxList->pxIndex;
    pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
    pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem;
    pxList->pxIndex = ( volatile xListItem * ) pxNewListItem;

    /* Remember which list the item is in. */
    pxNewListItem->pvContainer = ( void * ) pxList;

    ( pxList->uxNumberOfItems )++;
}