FreeRTOS源码解析 -> vTaskSuspend

来源:互联网 发布:日常流水账软件 编辑:程序博客网 时间:2024/06/05 06:34

    “挂起(suspended)”是非运行状态的子状态。处于挂起状态的任务对调度器而言是不可见的。让一个任务进入挂起状态的唯一办法就是调用vTaskSuspend() API函数;而把一个挂起状态的任务唤醒的唯一途径就是调用vTaskResume()或vTaskResumeFromISR() API函数。大多数应用程序中都不会用到挂起状态。

#if ( INCLUDE_vTaskSuspend == 1 )void vTaskSuspend( xTaskHandle pxTaskToSuspend ){tskTCB *pxTCB;        //用汇编关闭所有中断(保证我在对任务操作的时候不会因为中断而打断)taskENTER_CRITICAL();{/* Ensure a yield is performed if the current task is beingsuspended. */if( pxTaskToSuspend == pxCurrentTCB ){pxTaskToSuspend = NULL;}/* If null is passed in here then we are suspending ourselves. */pxTCB = prvGetTCBFromHandle( pxTaskToSuspend );//和删除类似的方法,都是通过上面两步找到实际要操作的tasktraceTASK_SUSPEND( pxTCB );/* Remove task from the ready/delayed list and place in thesuspended list. */vListRemove( &( pxTCB->xGenericListItem ) );/* Is the task waiting on an event also? *//* 看一下要挂起的task是否在阻塞态列表中有恢复到ready的event */if( pxTCB->xEventListItem.pvContainer ){//有的话删除,不让他通过event进入ready状态vListRemove( &( pxTCB->xEventListItem ) );}            //当前任务插入挂起列表最后vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );}//开中断taskEXIT_CRITICAL();        //如果挂起的是当前正在运行的任务if( ( void * ) pxTaskToSuspend == NULL ){/* 并且调度器是运行的,那么马上进行一次调度 */if( xSchedulerRunning != pdFALSE ){/* We have just suspended the current task. *//*强制上下文切换*/portYIELD_WITHIN_API();}//调度器没有在运行else{/* The scheduler is not running, but the task that was pointedto by pxCurrentTCB has just been suspended and pxCurrentTCBmust be adjusted to point to a different task. *///当前只有一个task,并且这个任务此时被挂起了if( uxCurrentNumberOfTasks == ( unsigned portBASE_TYPE ) 1U ){/* No other tasks are defined, so set pxCurrentTCB back toNULL so when the next task is created pxCurrentTCB willbe set to point to it no matter what its relative priorityis. */pxCurrentTCB = NULL;}else{vTaskSwitchContext();}}}}#endif


0 0
原创粉丝点击