From 5fba15483a1872cb076796db599f4314cb058d72 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Mon, 24 Sep 2012 12:05:35 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1784 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Source/croutine.c | 12 ++--- FreeRTOS/Source/include/list.h | 9 ++-- FreeRTOS/Source/list.c | 4 +- FreeRTOS/Source/tasks.c | 94 ++++++++++++++++++---------------- FreeRTOS/Source/timers.c | 6 +-- 5 files changed, 68 insertions(+), 57 deletions(-) diff --git a/FreeRTOS/Source/croutine.c b/FreeRTOS/Source/croutine.c index 0d62ca083..7d51aedef 100644 --- a/FreeRTOS/Source/croutine.c +++ b/FreeRTOS/Source/croutine.c @@ -203,7 +203,7 @@ portTickType xTimeToWake; /* 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. */ - vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + uxListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); /* The list item will be inserted in wake time order. */ listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); @@ -243,11 +243,11 @@ static void prvCheckPendingReadyList( void ) portDISABLE_INTERRUPTS(); { pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); - vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); } portENABLE_INTERRUPTS(); - vListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); } } @@ -293,12 +293,12 @@ corCRCB *pxCRCB; have been moved to the pending ready list and the following line is still valid. Also the pvContainer parameter will have 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? */ if( pxCRCB->xEventListItem.pvContainer ) { - vListRemove( &( pxCRCB->xEventListItem ) ); + uxListRemove( &( pxCRCB->xEventListItem ) ); } } portENABLE_INTERRUPTS(); @@ -370,7 +370,7 @@ signed portBASE_TYPE xReturn; event lists and the pending ready list. This function assumes that a check has already been made to ensure pxEventList is not empty. */ pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); - vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) diff --git a/FreeRTOS/Source/include/list.h b/FreeRTOS/Source/include/list.h index 20ecd867c..08a36b69b 100644 --- a/FreeRTOS/Source/include/list.h +++ b/FreeRTOS/Source/include/list.h @@ -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 * 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. + * + * @return The number of items that remain in the list after the list item has + * been removed. * - * \page vListRemove vListRemove + * \page uxListRemove uxListRemove * \ingroup LinkedList */ -void vListRemove( xListItem *pxItemToRemove ); +unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove ); #ifdef __cplusplus } diff --git a/FreeRTOS/Source/list.c b/FreeRTOS/Source/list.c index 9ae5d86e4..40e2bfd40 100644 --- a/FreeRTOS/Source/list.c +++ b/FreeRTOS/Source/list.c @@ -180,7 +180,7 @@ portTickType xValueOfInsertion; } /*-----------------------------------------------------------*/ -void vListRemove( xListItem *pxItemToRemove ) +unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove ) { xList * pxList; @@ -199,6 +199,8 @@ xList * pxList; pxItemToRemove->pvContainer = NULL; ( pxList->uxNumberOfItems )--; + + return pxList->uxNumberOfItems; } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 99a48c0c5..e04232b33 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -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. */ - #define taskCHECK_READY_LIST( uxPriority ) + #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority ) #else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ @@ -261,19 +261,6 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType ) listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ } /* 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 */ /* @@ -336,12 +323,12 @@ portTickType xItemValue; \ } \ \ /* 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? */ \ if( pxTCB->xEventListItem.pvContainer != NULL ) \ { \ - vListRemove( &( pxTCB->xEventListItem ) ); \ + uxListRemove( &( pxTCB->xEventListItem ) ); \ } \ prvAddTaskToReadyQueue( pxTCB ); \ } \ @@ -641,13 +628,15 @@ tskTCB * pxNewTCB; This will stop the task from be scheduled. The idle task will check the termination list and free up any memory allocated by the scheduler for the TCB and stack. */ - vListRemove( &( pxTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } /* Is the task waiting on an event also? */ if( pxTCB->xEventListItem.pvContainer != NULL ) { - vListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); } vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) ); @@ -734,8 +723,11 @@ tskTCB * pxNewTCB; /* 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. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } + prvAddCurrentTaskToDelayedList( xTimeToWake ); } } @@ -781,8 +773,10 @@ tskTCB * pxNewTCB; /* 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. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } prvAddCurrentTaskToDelayedList( xTimeToWake ); } xAlreadyYielded = xTaskResumeAll(); @@ -975,8 +969,10 @@ tskTCB * pxNewTCB; /* 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 can do this even if the scheduler is suspended. */ - vListRemove( &( pxTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( uxCurrentPriority ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( uxCurrentPriority, uxTopReadyPriority ); + } prvAddTaskToReadyQueue( pxTCB ); } @@ -1013,13 +1009,15 @@ tskTCB * pxNewTCB; traceTASK_SUSPEND( pxTCB ); /* Remove task from the ready/delayed list and place in the suspended list. */ - vListRemove( &( pxTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } /* Is the task waiting on an event also? */ if( pxTCB->xEventListItem.pvContainer != NULL ) { - vListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); } vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ); @@ -1116,7 +1114,7 @@ tskTCB * pxNewTCB; /* As we are in a critical section we can access the ready lists even if the scheduler is suspended. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); /* We may have just resumed a higher priority task. */ @@ -1157,7 +1155,7 @@ tskTCB * pxNewTCB; if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); } else @@ -1297,8 +1295,8 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE; while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE ) { pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ); - vListRemove( &( pxTCB->xEventListItem ) ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); /* 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 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. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } #if ( INCLUDE_vTaskSuspend == 1 ) { @@ -1836,8 +1836,10 @@ portTickType xTimeToWake; /* 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 function is called form a critical section. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxCurrentTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } /* Calculate the time at which the task should be woken if the event does not occur. This may overflow but this doesn't matter. */ @@ -1868,11 +1870,11 @@ portBASE_TYPE xReturn; pxEventList is not empty. */ pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); configASSERT( pxUnblockedTCB ); - vListRemove( &( pxUnblockedTCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { - vListRemove( &( pxUnblockedTCB->xGenericListItem ) ); + uxListRemove( &( pxUnblockedTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxUnblockedTCB ); } else @@ -2209,7 +2211,7 @@ static void prvCheckTasksWaitingTermination( void ) taskENTER_CRITICAL(); { pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); --uxCurrentNumberOfTasks; --uxTasksDeleted; } @@ -2517,8 +2519,10 @@ tskTCB *pxNewTCB; be moved in to a new list. */ if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE ) { - vListRemove( &( pxTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } /* Inherit the priority before being moved into the new list. */ pxTCB->uxPriority = pxCurrentTCB->uxPriority; @@ -2550,8 +2554,10 @@ tskTCB *pxNewTCB; { /* We must be the running task to be able to give the mutex back. Remove ourselves from the ready list we currently appear in. */ - vListRemove( &( pxTCB->xGenericListItem ) ); - taskCHECK_READY_LIST( pxTCB->uxPriority ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } /* Disinherit the priority before adding the task into the new ready list. */ diff --git a/FreeRTOS/Source/timers.c b/FreeRTOS/Source/timers.c index 0be294277..ef80cd2dd 100644 --- a/FreeRTOS/Source/timers.c +++ b/FreeRTOS/Source/timers.c @@ -312,7 +312,7 @@ portBASE_TYPE xResult; /* Remove the timer from the list of active timers. A check has already been performed to ensure the list is not empty. */ pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); - vListRemove( &( pxTimer->xTimerListItem ) ); + uxListRemove( &( pxTimer->xTimerListItem ) ); traceTIMER_EXPIRED( pxTimer ); /* 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 ) { /* 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. */ 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 it is an auto-reload timer. It cannot be restarted here as the lists -- 2.39.5