]> git.sur5r.net Git - freertos/commitdiff
Introduce prvResetNextTaskUnblockTime() to encapsulate functionality from various...
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 13 Dec 2013 10:35:11 +0000 (10:35 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 13 Dec 2013 10:35:11 +0000 (10:35 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2131 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/tasks.c

index 651d04648483e89e6fd7e11d969b6b3c5d4cf4f1..66723ae99817b1686a54a160d3fd0bd52f376264 100644 (file)
@@ -339,25 +339,7 @@ count overflows. */
        pxDelayedTaskList = pxOverflowDelayedTaskList;                                                                                                  \\r
        pxOverflowDelayedTaskList = pxTemp;                                                                                                                             \\r
        xNumOfOverflows++;                                                                                                                                                              \\r
-                                                                                                                                                                                                       \\r
-       if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )                                                                                 \\r
-       {                                                                                                                                                                                               \\r
-               /* The new current delayed list is empty.  Set                                                                                          \\r
-               xNextTaskUnblockTime to the maximum possible value so it is                                                                     \\r
-               extremely unlikely that the                                                                                                                                     \\r
-               if( xTickCount >= xNextTaskUnblockTime ) test will pass until                                                           \\r
-               there is an item in the delayed list. */                                                                                                        \\r
-               xNextTaskUnblockTime = portMAX_DELAY;                                                                                                           \\r
-       }                                                                                                                                                                                               \\r
-       else                                                                                                                                                                                    \\r
-       {                                                                                                                                                                                               \\r
-               /* The new current delayed list is not empty, get the value of                                                          \\r
-               the item at the head of the delayed list.  This is the time at                                                          \\r
-               which the task at the head of the delayed list should be removed                                                        \\r
-               from the Blocked state. */                                                                                                                                      \\r
-               pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );                                          \\r
-               xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );                         \\r
-       }                                                                                                                                                                                               \\r
+       prvResetNextTaskUnblockTime();                                                                                                                                  \\r
 }\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -483,6 +465,14 @@ static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TY
 \r
 #endif\r
 \r
+/*\r
+ * Set xNextTaskUnblockTime to the time at which the next Blocked state task\r
+ * will exit the Blocked state.\r
+ */\r
+static void prvResetNextTaskUnblockTime( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
 signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions )\r
 {\r
 signed portBASE_TYPE xReturn;\r
@@ -689,7 +679,7 @@ tskTCB * pxNewTCB;
 \r
                                /* The pre-delete hook is primarily for the Windows simulator,\r
                                in which Windows specific clean up operations are performed,\r
-                               after which it is not possible to yield away from this task - \r
+                               after which it is not possible to yield away from this task -\r
                                hence xYieldPending is used to latch that a context switch is\r
                                required. */\r
                                portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\r
@@ -697,10 +687,9 @@ tskTCB * pxNewTCB;
                        }\r
                        else\r
                        {\r
-                               /* Reset the next expected unblock time in case it referred to the task \r
-                               that has just been deleted. */\r
-                               pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
-                               xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
+                               /* Reset the next expected unblock time in case it referred to\r
+                               the task that has just been deleted. */\r
+                               prvResetNextTaskUnblockTime();\r
                        }\r
                }\r
        }\r
@@ -1076,7 +1065,7 @@ tskTCB * pxNewTCB;
 \r
                        traceTASK_SUSPEND( pxTCB );\r
 \r
-                       /* Remove task from the ready/delayed list and place in the     \r
+                       /* Remove task from the ready/delayed list and place in the\r
                        suspended list. */\r
                        if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
                        {\r
@@ -1124,11 +1113,10 @@ tskTCB * pxNewTCB;
                {\r
                        if( xSchedulerRunning != pdFALSE )\r
                        {\r
-                               /* A task other than the currently running task was suspended, reset\r
-                               the next expected unblock time in case it referred to the task that\r
-                               is now in the Suspended state. */\r
-                               pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
-                               xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
+                               /* A task other than the currently running task was suspended,\r
+                               reset the next expected unblock time in case it referred to the\r
+                               task that is now in the Suspended state. */\r
+                               prvResetNextTaskUnblockTime();\r
                        }\r
                }\r
        }\r
@@ -1663,9 +1651,9 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                                taskSWITCH_DELAYED_LISTS();\r
                        }\r
 \r
-                       /* See if this tick has made a timeout expire.  Tasks are stored in \r
-                       the     queue in the order of their wake time - meaning once one task \r
-                       has been found whose block time has not expired there is no need to \r
+                       /* See if this tick has made a timeout expire.  Tasks are stored in\r
+                       the     queue in the order of their wake time - meaning once one task\r
+                       has been found whose block time has not expired there is no need to\r
                        look any further        down the list. */\r
                        if( xConstTickCount >= xNextTaskUnblockTime )\r
                        {\r
@@ -1673,9 +1661,9 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                                {\r
                                        if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
                                        {\r
-                                               /* The delayed list is empty.  Set xNextTaskUnblockTime \r
-                                               to the maximum possible value so it is extremely \r
-                                               unlikely that the \r
+                                               /* The delayed list is empty.  Set xNextTaskUnblockTime\r
+                                               to the maximum possible value so it is extremely\r
+                                               unlikely that the\r
                                                if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
                                                next time through. */\r
                                                xNextTaskUnblockTime = portMAX_DELAY;\r
@@ -1683,19 +1671,19 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                                        }\r
                                        else\r
                                        {\r
-                                               /* The delayed list is not empty, get the value of the \r
-                                               item at the head of the delayed list.  This is the time \r
-                                               at which the task at the head of the delayed list must \r
+                                               /* The delayed list is not empty, get the value of the\r
+                                               item at the head of the delayed list.  This is the time\r
+                                               at which the task at the head of the delayed list must\r
                                                be removed from the Blocked state. */\r
                                                pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
                                                xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
 \r
                                                if( xConstTickCount < xItemValue )\r
                                                {\r
-                                                       /* It is not time to unblock this item yet, but the \r
-                                                       item value is the time at which the task at the head \r
-                                                       of the blocked list must be removed from the Blocked \r
-                                                       state - so record the item value in \r
+                                                       /* It is not time to unblock this item yet, but the\r
+                                                       item value is the time at which the task at the head\r
+                                                       of the blocked list must be removed from the Blocked\r
+                                                       state - so record the item value in\r
                                                        xNextTaskUnblockTime. */\r
                                                        xNextTaskUnblockTime = xItemValue;\r
                                                        break;\r
@@ -1704,7 +1692,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                                                /* It is time to remove the item from the Blocked state. */\r
                                                ( void ) uxListRemove( &( pxTCB->xGenericListItem ) );\r
 \r
-                                               /* Is the task waiting on an event also?  If so remove \r
+                                               /* Is the task waiting on an event also?  If so remove\r
                                                it from the event list. */\r
                                                if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                                                {\r
@@ -1715,13 +1703,13 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                                                list. */\r
                                                prvAddTaskToReadyList( pxTCB );\r
 \r
-                                               /* A task being unblocked cannot cause an immediate \r
+                                               /* A task being unblocked cannot cause an immediate\r
                                                context switch if preemption is turned off. */\r
                                                #if (  configUSE_PREEMPTION == 1 )\r
                                                {\r
-                                                       /* Preemption is on, but a context switch should \r
-                                                       only be performed if the unblocked task has a \r
-                                                       priority that is equal to or higher than the \r
+                                                       /* Preemption is on, but a context switch should\r
+                                                       only be performed if the unblocked task has a\r
+                                                       priority that is equal to or higher than the\r
                                                        currently executing task. */\r
                                                        if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
                                                        {\r
@@ -2782,6 +2770,31 @@ tskTCB *pxNewTCB;
 #endif /* INCLUDE_vTaskDelete */\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvResetNextTaskUnblockTime( void )\r
+{\r
+tskTCB *pxTCB;\r
+\r
+       if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
+       {\r
+               /* The new current delayed list is empty.  Set\r
+               xNextTaskUnblockTime to the maximum possible value so it is\r
+               extremely unlikely that the\r
+               if( xTickCount >= xNextTaskUnblockTime ) test will pass until\r
+               there is an item in the delayed list. */\r
+               xNextTaskUnblockTime = portMAX_DELAY;\r
+       }\r
+       else\r
+       {\r
+               /* The new current delayed list is not empty, get the value of\r
+               the item at the head of the delayed list.  This is the time at\r
+               which the task at the head of the delayed list should be removed\r
+               from the Blocked state. */\r
+               ( pxTCB ) = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+               xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xGenericListItem ) );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\r
 \r
        xTaskHandle xTaskGetCurrentTaskHandle( void )\r