\r
/*-----------------------------------------------------------*/\r
\r
+#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 0\r
+ /* \r
+ * uxTopReadyPriority holds the priority of the highest priority ready\r
+ * state task.\r
+ */\r
+ #define taskRECORD_READY_PRIORITY( uxPriority ) \\r
+ { \\r
+ if( ( uxPriority ) > uxTopReadyPriority ) \\r
+ { \\r
+ uxTopReadyPriority = ( uxPriority ); \\r
+ } \\r
+ } /* taskRECORD_READY_PRIORITY */\r
+\r
+ /*-----------------------------------------------------------*/\r
+\r
+ #define taskSELECT_HIGHEST_PRIORITY_TASK() \\r
+ { \\r
+ /* Find the highest priority queue that contains ready tasks. */ \\r
+ while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) ) \\r
+ { \\r
+ configASSERT( uxTopReadyPriority ); \\r
+ --uxTopReadyPriority; \\r
+ } \\r
+ \\r
+ /* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \\r
+ the same priority get an equal share of the processor time. */ \\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); \\r
+ } /* taskSELECT_HIGHEST_PRIORITY_TASK */\r
+\r
+ /*-----------------------------------------------------------*/\r
+\r
+ /* Define away taskCHECK_READY_LIST() as it is not required in this\r
+ configuration. */\r
+ #define taskCHECK_READY_LIST( uxPriority )\r
+\r
+#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
+\r
+ /* A port optimised version is provided. Call the port defined macros. */\r
+ #define taskRECORD_READY_PRIORITY( uxPriority ) portRECORD_READY_PRIORITY( uxPriority, uxTopReadyPriority )\r
+\r
+ /*-----------------------------------------------------------*/\r
+\r
+ #define taskSELECT_HIGHEST_PRIORITY_TASK() \\r
+ { \\r
+ unsigned portBASE_TYPE uxTopPriority; \\r
+ \\r
+ /* Find the highest priority queue that contains ready tasks. */ \\r
+ portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \\r
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \\r
+ } /* taskSELECT_HIGHEST_PRIORITY_TASK() */\r
+\r
+ /*-----------------------------------------------------------*/\r
+\r
+ /* Let the port layer know if the ready list is empty so \r
+ taskSELECT_HIGHEST_PRIORITY_TASK() can function correctly. */\r
+ #define taskCHECK_READY_LIST( uxPriority ) \\r
+ { \\r
+ if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == 0 ) \\r
+ { \\r
+ portRESET_READY_PRIORITY( ( uxPriority ), uxTopReadyPriority ); \\r
+ } \\r
+ } /* taskCHECK_READY_LIST() */\r
+\r
+\r
+#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
+\r
/*\r
* Place the task represented by pxTCB into the appropriate ready queue for\r
* the task. It is inserted at the end of the list. One quirk of this is\r
*/\r
#define prvAddTaskToReadyQueue( pxTCB ) \\r
traceMOVED_TASK_TO_READY_STATE( pxTCB ) \\r
- if( ( pxTCB )->uxPriority > uxTopReadyPriority ) \\r
- { \\r
- uxTopReadyPriority = ( pxTCB )->uxPriority; \\r
- } \\r
+ taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \\r
vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) )\r
/*-----------------------------------------------------------*/\r
\r
the termination list and free up any memory allocated by the\r
scheduler for the TCB and stack. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxTCB->uxPriority );\r
\r
/* Is the task waiting on an event also? */\r
if( pxTCB->xEventListItem.pvContainer != NULL )\r
ourselves to the blocked list as the same list item is used for\r
both lists. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxCurrentTCB->uxPriority );\r
prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
}\r
ourselves to the blocked list as the same list item is used for\r
both lists. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxCurrentTCB->uxPriority );\r
prvAddCurrentTaskToDelayedList( xTimeToWake );\r
}\r
xAlreadyYielded = xTaskResumeAll();\r
it to it's new ready list. As we are in a critical section we\r
can do this even if the scheduler is suspended. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( uxCurrentPriority );\r
prvAddTaskToReadyQueue( pxTCB );\r
}\r
\r
\r
/* Remove task from the ready/delayed list and place in the suspended list. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxTCB->uxPriority );\r
\r
/* Is the task waiting on an event also? */\r
if( pxTCB->xEventListItem.pvContainer != NULL )\r
taskFIRST_CHECK_FOR_STACK_OVERFLOW();\r
taskSECOND_CHECK_FOR_STACK_OVERFLOW();\r
\r
- /* Find the highest priority queue that contains ready tasks. */\r
- while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) )\r
- {\r
- configASSERT( uxTopReadyPriority );\r
- --uxTopReadyPriority;\r
- }\r
- \r
- /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the\r
- same priority get an equal share of the processor time. */\r
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );\r
- \r
+ taskSELECT_HIGHEST_PRIORITY_TASK();\r
+ \r
traceTASK_SWITCHED_IN();\r
}\r
}\r
to the blocked list as the same list item is used for both lists. We have\r
exclusive access to the ready lists as the scheduler is locked. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
-\r
+ taskCHECK_READY_LIST( pxCurrentTCB->uxPriority );\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
{\r
blocked list as the same list item is used for both lists. This\r
function is called form a critical section. */\r
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxCurrentTCB->uxPriority );\r
\r
/* Calculate the time at which the task should be woken if the event does\r
not occur. This may overflow but this doesn't matter. */\r
if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
{\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxTCB->uxPriority );\r
\r
/* Inherit the priority before being moved into the new list. */\r
pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
/* We must be the running task to be able to give the mutex back.\r
Remove ourselves from the ready list we currently appear in. */\r
vListRemove( &( pxTCB->xGenericListItem ) );\r
+ taskCHECK_READY_LIST( pxTCB->uxPriority );\r
\r
/* Disinherit the priority before adding the task into the new\r
ready list. */\r