Replace the need for taskCHECK_READY_LIST() by instead making vListRemove() return the number of items that remain in the list once the list item has been removed.

pull/4/head
Richard Barry 13 years ago
parent 18a4b00a18
commit 42a11edef8

@ -203,7 +203,7 @@ portTickType xTimeToWake;
/* We must remove ourselves from the ready list before adding /* We must remove ourselves from the ready list before adding
ourselves to the blocked list as the same list item is used for ourselves to the blocked list as the same list item is used for
both lists. */ both lists. */
vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); uxListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
/* The list item will be inserted in wake time order. */ /* The list item will be inserted in wake time order. */
listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
@ -243,11 +243,11 @@ static void prvCheckPendingReadyList( void )
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
{ {
pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );
vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
} }
portENABLE_INTERRUPTS(); portENABLE_INTERRUPTS();
vListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) );
prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
} }
} }
@ -293,12 +293,12 @@ corCRCB *pxCRCB;
have been moved to the pending ready list and the following have been moved to the pending ready list and the following
line is still valid. Also the pvContainer parameter will have line is still valid. Also the pvContainer parameter will have
been set to NULL so the following lines are also valid. */ been set to NULL so the following lines are also valid. */
vListRemove( &( pxCRCB->xGenericListItem ) ); uxListRemove( &( pxCRCB->xGenericListItem ) );
/* Is the co-routine waiting on an event also? */ /* Is the co-routine waiting on an event also? */
if( pxCRCB->xEventListItem.pvContainer ) if( pxCRCB->xEventListItem.pvContainer )
{ {
vListRemove( &( pxCRCB->xEventListItem ) ); uxListRemove( &( pxCRCB->xEventListItem ) );
} }
} }
portENABLE_INTERRUPTS(); portENABLE_INTERRUPTS();
@ -370,7 +370,7 @@ signed portBASE_TYPE xReturn;
event lists and the pending ready list. This function assumes that a event lists and the pending ready list. This function assumes that a
check has already been made to ensure pxEventList is not empty. */ check has already been made to ensure pxEventList is not empty. */
pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );
if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )

@ -329,13 +329,16 @@ void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );
* Remove an item from a list. The list item has a pointer to the list that * Remove an item from a list. The list item has a pointer to the list that
* it is in, so only the list item need be passed into the function. * it is in, so only the list item need be passed into the function.
* *
* @param vListRemove The item to be removed. The item will remove itself from * @param uxListRemove The item to be removed. The item will remove itself from
* the list pointed to by it's pxContainer parameter. * the list pointed to by it's pxContainer parameter.
* *
* \page vListRemove vListRemove * @return The number of items that remain in the list after the list item has
* been removed.
*
* \page uxListRemove uxListRemove
* \ingroup LinkedList * \ingroup LinkedList
*/ */
void vListRemove( xListItem *pxItemToRemove ); unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove );
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -180,7 +180,7 @@ portTickType xValueOfInsertion;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vListRemove( xListItem *pxItemToRemove ) unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove )
{ {
xList * pxList; xList * pxList;
@ -199,6 +199,8 @@ xList * pxList;
pxItemToRemove->pvContainer = NULL; pxItemToRemove->pvContainer = NULL;
( pxList->uxNumberOfItems )--; ( pxList->uxNumberOfItems )--;
return pxList->uxNumberOfItems;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

@ -241,9 +241,9 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Define away taskCHECK_READY_LIST() as it is not required in this /* Define away portRESET_READY_PRIORITY() as it is not required in this
configuration. */ configuration. */
#define taskCHECK_READY_LIST( uxPriority ) #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority )
#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ #else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
@ -261,19 +261,6 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType )
listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \
} /* taskSELECT_HIGHEST_PRIORITY_TASK() */ } /* taskSELECT_HIGHEST_PRIORITY_TASK() */
/*-----------------------------------------------------------*/
/* Let the port layer know if the ready list is empty so
taskSELECT_HIGHEST_PRIORITY_TASK() can function correctly. */
#define taskCHECK_READY_LIST( uxPriority ) \
{ \
if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == 0 ) \
{ \
portRESET_READY_PRIORITY( ( uxPriority ), uxTopReadyPriority ); \
} \
} /* taskCHECK_READY_LIST() */
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
/* /*
@ -336,12 +323,12 @@ portTickType xItemValue; \
} \ } \
\ \
/* It is time to remove the item from the Blocked state. */ \ /* It is time to remove the item from the Blocked state. */ \
vListRemove( &( pxTCB->xGenericListItem ) ); \ uxListRemove( &( pxTCB->xGenericListItem ) ); \
\ \
/* Is the task waiting on an event also? */ \ /* Is the task waiting on an event also? */ \
if( pxTCB->xEventListItem.pvContainer != NULL ) \ if( pxTCB->xEventListItem.pvContainer != NULL ) \
{ \ { \
vListRemove( &( pxTCB->xEventListItem ) ); \ uxListRemove( &( pxTCB->xEventListItem ) ); \
} \ } \
prvAddTaskToReadyQueue( pxTCB ); \ prvAddTaskToReadyQueue( pxTCB ); \
} \ } \
@ -641,13 +628,15 @@ tskTCB * pxNewTCB;
This will stop the task from be scheduled. The idle task will check This will stop the task from be scheduled. The idle task will check
the termination list and free up any memory allocated by the the termination list and free up any memory allocated by the
scheduler for the TCB and stack. */ scheduler for the TCB and stack. */
vListRemove( &( pxTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );
}
/* Is the task waiting on an event also? */ /* Is the task waiting on an event also? */
if( pxTCB->xEventListItem.pvContainer != NULL ) if( pxTCB->xEventListItem.pvContainer != NULL )
{ {
vListRemove( &( pxTCB->xEventListItem ) ); uxListRemove( &( pxTCB->xEventListItem ) );
} }
vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) ); vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );
@ -734,8 +723,11 @@ tskTCB * pxNewTCB;
/* We must remove ourselves from the ready list before adding /* We must remove ourselves from the ready list before adding
ourselves to the blocked list as the same list item is used for ourselves to the blocked list as the same list item is used for
both lists. */ both lists. */
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );
}
prvAddCurrentTaskToDelayedList( xTimeToWake ); prvAddCurrentTaskToDelayedList( xTimeToWake );
} }
} }
@ -781,8 +773,10 @@ tskTCB * pxNewTCB;
/* We must remove ourselves from the ready list before adding /* We must remove ourselves from the ready list before adding
ourselves to the blocked list as the same list item is used for ourselves to the blocked list as the same list item is used for
both lists. */ both lists. */
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );
}
prvAddCurrentTaskToDelayedList( xTimeToWake ); prvAddCurrentTaskToDelayedList( xTimeToWake );
} }
xAlreadyYielded = xTaskResumeAll(); xAlreadyYielded = xTaskResumeAll();
@ -975,8 +969,10 @@ tskTCB * pxNewTCB;
/* The task is currently in its ready list - remove before adding /* The task is currently in its ready list - remove before adding
it to it's new ready list. As we are in a critical section we it to it's new ready list. As we are in a critical section we
can do this even if the scheduler is suspended. */ can do this even if the scheduler is suspended. */
vListRemove( &( pxTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( uxCurrentPriority ); {
portRESET_READY_PRIORITY( uxCurrentPriority, uxTopReadyPriority );
}
prvAddTaskToReadyQueue( pxTCB ); prvAddTaskToReadyQueue( pxTCB );
} }
@ -1013,13 +1009,15 @@ tskTCB * pxNewTCB;
traceTASK_SUSPEND( pxTCB ); traceTASK_SUSPEND( pxTCB );
/* Remove task from the ready/delayed list and place in the suspended list. */ /* Remove task from the ready/delayed list and place in the suspended list. */
vListRemove( &( pxTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );
}
/* Is the task waiting on an event also? */ /* Is the task waiting on an event also? */
if( pxTCB->xEventListItem.pvContainer != NULL ) if( pxTCB->xEventListItem.pvContainer != NULL )
{ {
vListRemove( &( pxTCB->xEventListItem ) ); uxListRemove( &( pxTCB->xEventListItem ) );
} }
vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ); vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );
@ -1116,7 +1114,7 @@ tskTCB * pxNewTCB;
/* As we are in a critical section we can access the ready /* As we are in a critical section we can access the ready
lists even if the scheduler is suspended. */ lists even if the scheduler is suspended. */
vListRemove( &( pxTCB->xGenericListItem ) ); uxListRemove( &( pxTCB->xGenericListItem ) );
prvAddTaskToReadyQueue( pxTCB ); prvAddTaskToReadyQueue( pxTCB );
/* We may have just resumed a higher priority task. */ /* We may have just resumed a higher priority task. */
@ -1157,7 +1155,7 @@ tskTCB * pxNewTCB;
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
{ {
xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ); xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );
vListRemove( &( pxTCB->xGenericListItem ) ); uxListRemove( &( pxTCB->xGenericListItem ) );
prvAddTaskToReadyQueue( pxTCB ); prvAddTaskToReadyQueue( pxTCB );
} }
else else
@ -1297,8 +1295,8 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE;
while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE ) while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE )
{ {
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ); pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) );
vListRemove( &( pxTCB->xEventListItem ) ); uxListRemove( &( pxTCB->xEventListItem ) );
vListRemove( &( pxTCB->xGenericListItem ) ); uxListRemove( &( pxTCB->xGenericListItem ) );
prvAddTaskToReadyQueue( pxTCB ); prvAddTaskToReadyQueue( pxTCB );
/* If we have moved a task that has a priority higher than /* If we have moved a task that has a priority higher than
@ -1782,8 +1780,10 @@ portTickType xTimeToWake;
/* We must remove ourselves from the ready list before adding ourselves /* We must remove ourselves from the ready list before adding ourselves
to the blocked list as the same list item is used for both lists. We have to the blocked list as the same list item is used for both lists. We have
exclusive access to the ready lists as the scheduler is locked. */ exclusive access to the ready lists as the scheduler is locked. */
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );
}
#if ( INCLUDE_vTaskSuspend == 1 ) #if ( INCLUDE_vTaskSuspend == 1 )
{ {
@ -1836,8 +1836,10 @@ portTickType xTimeToWake;
/* We must remove this task from the ready list before adding it to the /* We must remove this task from the ready list before adding it to the
blocked list as the same list item is used for both lists. This blocked list as the same list item is used for both lists. This
function is called form a critical section. */ function is called form a critical section. */
vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );
}
/* Calculate the time at which the task should be woken if the event does /* Calculate the time at which the task should be woken if the event does
not occur. This may overflow but this doesn't matter. */ not occur. This may overflow but this doesn't matter. */
@ -1868,11 +1870,11 @@ portBASE_TYPE xReturn;
pxEventList is not empty. */ pxEventList is not empty. */
pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
configASSERT( pxUnblockedTCB ); configASSERT( pxUnblockedTCB );
vListRemove( &( pxUnblockedTCB->xEventListItem ) ); uxListRemove( &( pxUnblockedTCB->xEventListItem ) );
if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )
{ {
vListRemove( &( pxUnblockedTCB->xGenericListItem ) ); uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );
prvAddTaskToReadyQueue( pxUnblockedTCB ); prvAddTaskToReadyQueue( pxUnblockedTCB );
} }
else else
@ -2209,7 +2211,7 @@ static void prvCheckTasksWaitingTermination( void )
taskENTER_CRITICAL(); taskENTER_CRITICAL();
{ {
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) ); pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );
vListRemove( &( pxTCB->xGenericListItem ) ); uxListRemove( &( pxTCB->xGenericListItem ) );
--uxCurrentNumberOfTasks; --uxCurrentNumberOfTasks;
--uxTasksDeleted; --uxTasksDeleted;
} }
@ -2517,8 +2519,10 @@ tskTCB *pxNewTCB;
be moved in to a new list. */ be moved in to a new list. */
if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE ) if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )
{ {
vListRemove( &( pxTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );
}
/* Inherit the priority before being moved into the new list. */ /* Inherit the priority before being moved into the new list. */
pxTCB->uxPriority = pxCurrentTCB->uxPriority; pxTCB->uxPriority = pxCurrentTCB->uxPriority;
@ -2550,8 +2554,10 @@ tskTCB *pxNewTCB;
{ {
/* We must be the running task to be able to give the mutex back. /* We must be the running task to be able to give the mutex back.
Remove ourselves from the ready list we currently appear in. */ Remove ourselves from the ready list we currently appear in. */
vListRemove( &( pxTCB->xGenericListItem ) ); if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )
taskCHECK_READY_LIST( pxTCB->uxPriority ); {
portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );
}
/* Disinherit the priority before adding the task into the new /* Disinherit the priority before adding the task into the new
ready list. */ ready list. */

@ -312,7 +312,7 @@ portBASE_TYPE xResult;
/* Remove the timer from the list of active timers. A check has already /* Remove the timer from the list of active timers. A check has already
been performed to ensure the list is not empty. */ been performed to ensure the list is not empty. */
pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
vListRemove( &( pxTimer->xTimerListItem ) ); uxListRemove( &( pxTimer->xTimerListItem ) );
traceTIMER_EXPIRED( pxTimer ); traceTIMER_EXPIRED( pxTimer );
/* If the timer is an auto reload timer then calculate the next /* If the timer is an auto reload timer then calculate the next
@ -526,7 +526,7 @@ portTickType xTimeNow;
if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )
{ {
/* The timer is in a list, remove it. */ /* The timer is in a list, remove it. */
vListRemove( &( pxTimer->xTimerListItem ) ); uxListRemove( &( pxTimer->xTimerListItem ) );
} }
} }
@ -596,7 +596,7 @@ portBASE_TYPE xResult;
/* Remove the timer from the list. */ /* Remove the timer from the list. */
pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
vListRemove( &( pxTimer->xTimerListItem ) ); uxListRemove( &( pxTimer->xTimerListItem ) );
/* Execute its callback, then send a command to restart the timer if /* Execute its callback, then send a command to restart the timer if
it is an auto-reload timer. It cannot be restarted here as the lists it is an auto-reload timer. It cannot be restarted here as the lists

Loading…
Cancel
Save