添加任务到就绪列表

static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )

uxCurrentNumberOfTasks++; 当前的任务数量加一(PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks     = ( UBaseType_t ) 0U;)初始值为0

if( pxCurrentTCB == NULL )//没有任务在执行

if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 )
     
                /* This is the first task to be created so do the preliminary   initialisation required.  We will not recover if this call    fails, but we will report the failure. */

这个任务是第一个任务,所以要进行任务初始化,内部是初始化就绪、延时、挂起、等任务列表
                prvInitialiseTaskLists();

static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
{
    /* Ensure interrupts don't access the task lists while the lists are being
    updated. */
    taskENTER_CRITICAL();//进入临界区,仅关闭中断优先级小于5(可设置)的中断
    {
        uxCurrentNumberOfTasks++;//除去挂起的当前所有的任务数量加一(下面还有一个)
        if( pxCurrentTCB == NULL )//判断有任务在执行吗变量TCB_t * volatile pxCurrentTCB                                                         //=NULL;指向当前任务(是一个任务控制块)
        {
            /* There are no other tasks, or all the other tasks are in
            the suspended state - make this the current task. */
            pxCurrentTCB = pxNewTCB;//指向当前任务

            if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 )
            {
                /* This is the first task to be created so do the preliminary
                initialisation required.  We will not recover if this call
                fails, but we will report the failure. */
                prvInitialiseTaskLists();//这个任务是第一个任务,所以要进行任务初始化,内部是初始化                                                //                                就绪、延时、挂起、等任务列表,


            }
            else
            {
                mtCOVERAGE_TEST_MARKER();
            }
        }
        else
        {
            /* If the scheduler is not already running, make this task the
            current task if it is the highest priority task to be created
            so far. */
            if( xSchedulerRunning == pdFALSE )
            {
                if( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority )//判断新加入的任务的优先级
                {
                    pxCurrentTCB = pxNewTCB;
                }
                else
                {
                    mtCOVERAGE_TEST_MARKER();
                }
            }
            else
            {
                mtCOVERAGE_TEST_MARKER();
            }
        }

        uxTaskNumber++;//总的任务数量,包括挂起的任务(上面的不包括)

       

        prvAddTaskToReadyList( pxNewTCB );//放在下面
    }
    taskEXIT_CRITICAL();//退出,可以进行任务切换了,任务切换需要中断,上面把中断关了   
}

prvAddTaskToReadyList( pxNewTCB );

vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); 

&( pxReadyTasksLists[ ( pxTCB )->uxPriority ] )//新增任务的优先级(就绪列表又根据优先级分类)例如pxReadyTasksLists[3]

&( ( pxTCB )->xStateListItem )//根据状态列表插入到列表的最后


void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
{
ListItem_t * const pxIndex = pxList->pxIndex;\


    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 )++;
}


/*-----------------------------------------------------------*/


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值