]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Replace the need for taskCHECK_READY_LIST() by instead making vListRemove() return...
[freertos] / FreeRTOS / Source / tasks.c
index 99a48c0c504e1ee17087982450c05026fffe3d7f..e04232b33b7b67a08553121c4959e8f4632151e4 100644 (file)
@@ -241,9 +241,9 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime                                            = ( portTickType )
 \r
        /*-----------------------------------------------------------*/\r
 \r
-       /* Define away taskCHECK_READY_LIST() as it is not required in this\r
+       /* Define away portRESET_READY_PRIORITY() as it is not required in this\r
        configuration. */\r
-       #define taskCHECK_READY_LIST( uxPriority )\r
+       #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority )\r
 \r
 #else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
 \r
@@ -261,19 +261,6 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime                                           = ( portTickType )
                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
@@ -336,12 +323,12 @@ portTickType xItemValue;                                                                                                                          \
                                }                                                                                                                                               \\r
                                                                                                                                                                                \\r
                                /* It is time to remove the item from the Blocked state. */                             \\r
-                               vListRemove( &( pxTCB->xGenericListItem ) );                                                    \\r
+                               uxListRemove( &( pxTCB->xGenericListItem ) );                                                   \\r
                                                                                                                                                                                \\r
                                /* Is the task waiting on an event also? */                                                             \\r
                                if( pxTCB->xEventListItem.pvContainer != NULL )                                                 \\r
                                {                                                                                                                                               \\r
-                                       vListRemove( &( pxTCB->xEventListItem ) );                                                      \\r
+                                       uxListRemove( &( pxTCB->xEventListItem ) );                                                     \\r
                                }                                                                                                                                               \\r
                                prvAddTaskToReadyQueue( pxTCB );                                                                                \\r
                        }                                                                                                                                                       \\r
@@ -641,13 +628,15 @@ tskTCB * pxNewTCB;
                        This will stop the task from be scheduled.  The idle task will check\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
+                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                       {\r
+                               portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );\r
+                       }\r
 \r
                        /* Is the task waiting on an event also? */\r
                        if( pxTCB->xEventListItem.pvContainer != NULL )\r
                        {\r
-                               vListRemove( &( pxTCB->xEventListItem ) );\r
+                               uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
 \r
                        vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) );\r
@@ -734,8 +723,11 @@ tskTCB * pxNewTCB;
                                /* We must remove ourselves from the ready list before adding\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
+                               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+                               {\r
+                                       portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+                               }\r
+\r
                                prvAddCurrentTaskToDelayedList( xTimeToWake );\r
                        }\r
                }\r
@@ -781,8 +773,10 @@ tskTCB * pxNewTCB;
                                /* We must remove ourselves from the ready list before adding\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
+                               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+                               {\r
+                                       portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+                               }\r
                                prvAddCurrentTaskToDelayedList( xTimeToWake );\r
                        }\r
                        xAlreadyYielded = xTaskResumeAll();\r
@@ -975,8 +969,10 @@ tskTCB * pxNewTCB;
                                        /* The task is currently in its ready list - remove before adding\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
+                                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                                       {\r
+                                               portRESET_READY_PRIORITY( uxCurrentPriority, uxTopReadyPriority );\r
+                                       }\r
                                        prvAddTaskToReadyQueue( pxTCB );\r
                                }\r
 \r
@@ -1013,13 +1009,15 @@ tskTCB * pxNewTCB;
                        traceTASK_SUSPEND( pxTCB );\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
+                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                       {\r
+                               portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );\r
+                       }\r
 \r
                        /* Is the task waiting on an event also? */\r
                        if( pxTCB->xEventListItem.pvContainer != NULL )\r
                        {\r
-                               vListRemove( &( pxTCB->xEventListItem ) );\r
+                               uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
 \r
                        vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );\r
@@ -1116,7 +1114,7 @@ tskTCB * pxNewTCB;
 \r
                                        /* As we are in a critical section we can access the ready\r
                                        lists even if the scheduler is suspended. */\r
-                                       vListRemove(  &( pxTCB->xGenericListItem ) );\r
+                                       uxListRemove(  &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyQueue( pxTCB );\r
 \r
                                        /* We may have just resumed a higher priority task. */\r
@@ -1157,7 +1155,7 @@ tskTCB * pxNewTCB;
                                if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
                                {\r
                                        xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );\r
-                                       vListRemove(  &( pxTCB->xGenericListItem ) );\r
+                                       uxListRemove(  &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyQueue( pxTCB );\r
                                }\r
                                else\r
@@ -1297,8 +1295,8 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE;
                                while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE )\r
                                {\r
                                        pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY(  ( ( xList * ) &xPendingReadyList ) );\r
-                                       vListRemove( &( pxTCB->xEventListItem ) );\r
-                                       vListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       uxListRemove( &( pxTCB->xEventListItem ) );\r
+                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
                                        prvAddTaskToReadyQueue( pxTCB );\r
 \r
                                        /* If we have moved a task that has a priority higher than\r
@@ -1782,8 +1780,10 @@ portTickType xTimeToWake;
        /* We must remove ourselves from the ready list before adding ourselves\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
-       taskCHECK_READY_LIST( pxCurrentTCB->uxPriority );\r
+       if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+       {\r
+               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+       }\r
 \r
        #if ( INCLUDE_vTaskSuspend == 1 )\r
        {\r
@@ -1836,8 +1836,10 @@ portTickType xTimeToWake;
                /* We must remove this task from the ready list before adding it to the\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
+               if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 )\r
+               {\r
+                       portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+               }\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
@@ -1868,11 +1870,11 @@ portBASE_TYPE xReturn;
        pxEventList is not empty. */\r
        pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
        configASSERT( pxUnblockedTCB );\r
-       vListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
+       uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\r
 \r
        if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
        {\r
-               vListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
+               uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
                prvAddTaskToReadyQueue( pxUnblockedTCB );\r
        }\r
        else\r
@@ -2209,7 +2211,7 @@ static void prvCheckTasksWaitingTermination( void )
                                taskENTER_CRITICAL();\r
                                {\r
                                        pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );\r
-                                       vListRemove( &( pxTCB->xGenericListItem ) );\r
+                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
                                        --uxCurrentNumberOfTasks;\r
                                        --uxTasksDeleted;\r
                                }\r
@@ -2517,8 +2519,10 @@ tskTCB *pxNewTCB;
                                be moved in to a new list. */\r
                                if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE )\r
                                {\r
-                                       vListRemove( &( pxTCB->xGenericListItem ) );\r
-                                       taskCHECK_READY_LIST( pxTCB->uxPriority );\r
+                                       if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                                       {\r
+                                               portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );\r
+                                       }\r
 \r
                                        /* Inherit the priority before being moved into the new list. */\r
                                        pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
@@ -2550,8 +2554,10 @@ tskTCB *pxNewTCB;
                        {\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
+                               if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 )\r
+                               {\r
+                                       portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );\r
+                               }\r
 \r
                                /* Disinherit the priority before adding the task into the new\r
                                ready list. */\r