]> git.sur5r.net Git - freertos/commitdiff
Kernel optimisations.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 12 Jul 2013 11:11:19 +0000 (11:11 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 12 Jul 2013 11:11:19 +0000 (11:11 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1972 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/include/list.h
FreeRTOS/Source/list.c
FreeRTOS/Source/portable/IAR/ARM_CA9/portmacro.h
FreeRTOS/Source/queue.c
FreeRTOS/Source/tasks.c

index b5ab2fc6f67a48094f50cda472e8e6284297c205..934fd2afb9293a175d40cbd5ebb26ac340bac3f5 100644 (file)
     ***************************************************************************\r
 \r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
     license and Real Time Engineers Ltd. contact details.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
     fully thread aware and reentrant UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
-    Integrity Systems, who sell the code with commercial support, \r
+    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+    Integrity Systems, who sell the code with commercial support,\r
     indemnification and middleware, under the OpenRTOS brand.\r
-    \r
-    http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
-    engineered and independently SIL3 certified version for use in safety and \r
+\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
     mission critical applications that require provable dependability.\r
 */\r
 \r
 #ifndef LIST_H\r
 #define LIST_H\r
 \r
+/*\r
+ * The list structure members are modified from within interrupts, and therefore\r
+ * by rights should be declared volatile.  However, they are only modified in a\r
+ * functionally atomic way (within critical sections of with the scheduler\r
+ * suspended) and are either passed by reference into a function or indexed via\r
+ * a volatile variable.  Therefore, in all use cases tested so far, the volatile\r
+ * qualifier can be omitted in order to provide a moderate performance\r
+ * improvement without adversely affecting functional behaviour.  The assembly\r
+ * instructions generated by the IAR, ARM and GCC compilers when the respective\r
+ * compiler's options were set for maximum optimisation has been inspected and\r
+ * deemed to be as intended.  That said, as compiler technology advances, and\r
+ * especially if aggressive cross module optimisation is used (a use case that\r
+ * has not been exercised to any great extend) then it is feasible that the\r
+ * volatile qualifier will be needed for correct optimisation.  It is expected\r
+ * that a compiler removing essential code because, without the volatile\r
+ * qualifier on the list structure members and with aggressive cross module\r
+ * optimisation, the compiler deemed the code unnecessary will result in\r
+ * complete and obvious failure of the scheduler.  If this is ever experienced\r
+ * then the volatile qualifier can be inserted in the relevant places within the\r
+ * list structures by simply defining configLIST_VOLATILE to volatile in\r
+ * FreeRTOSConfig.h (as per the example at the bottom of this comment block).  \r
+ * If configLIST_VOLATILE is not defined then the preprocessor directives below \r
+ * will simply #define configLIST_VOLATILE away completely.\r
+ *\r
+ * To use volatile list structure members then add the following line to\r
+ * FreeRTOSConfig.h (without the quotes):\r
+ * "#define configLIST_VOLATILE volatile"\r
+ */\r
+#ifndef configLIST_VOLATILE\r
+       #define configLIST_VOLATILE\r
+#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */\r
+\r
 #ifdef __cplusplus\r
 extern "C" {\r
 #endif\r
@@ -112,19 +144,19 @@ extern "C" {
  */\r
 struct xLIST_ITEM\r
 {\r
-       portTickType xItemValue;                                /*< The value being listed.  In most cases this is used to sort the list in descending order. */\r
-       volatile struct xLIST_ITEM * pxNext;    /*< Pointer to the next xListItem in the list. */\r
-       volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */\r
-       void * pvOwner;                                                 /*< Pointer to the object (normally a TCB) that contains the list item.  There is therefore a two way link between the object containing the list item and the list item itself. */\r
-       void * pvContainer;                                             /*< Pointer to the list in which this list item is placed (if any). */\r
+       configLIST_VOLATILE portTickType xItemValue;    /*< The value being listed.  In most cases this is used to sort the list in descending order. */\r
+       struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next xListItem in the list. */\r
+       struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;/*< Pointer to the previous xListItem in the list. */\r
+       void * pvOwner;                                                                 /*< Pointer to the object (normally a TCB) that contains the list item.  There is therefore a two way link between the object containing the list item and the list item itself. */\r
+       void * configLIST_VOLATILE pvContainer;                 /*< Pointer to the list in which this list item is placed (if any). */\r
 };\r
-typedef struct xLIST_ITEM xListItem;           /* For some reason lint wants this as two separate definitions. */\r
+typedef struct xLIST_ITEM xListItem;                           /* For some reason lint wants this as two separate definitions. */\r
 \r
 struct xMINI_LIST_ITEM\r
 {\r
-       portTickType xItemValue;\r
-       volatile struct xLIST_ITEM *pxNext;\r
-       volatile struct xLIST_ITEM *pxPrevious;\r
+       configLIST_VOLATILE portTickType xItemValue;\r
+       struct xLIST_ITEM * configLIST_VOLATILE pxNext;\r
+       struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;\r
 };\r
 typedef struct xMINI_LIST_ITEM xMiniListItem;\r
 \r
@@ -133,9 +165,9 @@ typedef struct xMINI_LIST_ITEM xMiniListItem;
  */\r
 typedef struct xLIST\r
 {\r
-       volatile unsigned portBASE_TYPE uxNumberOfItems;\r
-       volatile xListItem * pxIndex;                   /*< Used to walk through the list.  Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */\r
-       volatile xMiniListItem xListEnd;                /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */\r
+       configLIST_VOLATILE unsigned portBASE_TYPE uxNumberOfItems;\r
+       xListItem * configLIST_VOLATILE pxIndex;                /*< Used to walk through the list.  Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */\r
+       xMiniListItem xListEnd;                                                 /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */\r
 } xList;\r
 \r
 /*\r
@@ -286,7 +318,7 @@ xList * const pxConstList = ( pxList );                                                                                                     \
  * \page vListInitialise vListInitialise\r
  * \ingroup LinkedList\r
  */\r
-void vListInitialise( xList *pxList );\r
+void vListInitialise( xList * const pxList );\r
 \r
 /*\r
  * Must be called before a list item is used.  This sets the list container to\r
@@ -297,7 +329,7 @@ void vListInitialise( xList *pxList );
  * \page vListInitialiseItem vListInitialiseItem\r
  * \ingroup LinkedList\r
  */\r
-void vListInitialiseItem( xListItem *pxItem );\r
+void vListInitialiseItem( xListItem * const pxItem );\r
 \r
 /*\r
  * Insert a list item into a list.  The item will be inserted into the list in\r
@@ -310,7 +342,7 @@ void vListInitialiseItem( xListItem *pxItem );
  * \page vListInsert vListInsert\r
  * \ingroup LinkedList\r
  */\r
-void vListInsert( xList *pxList, xListItem *pxNewListItem );\r
+void vListInsert( xList * const pxList, xListItem * const pxNewListItem );\r
 \r
 /*\r
  * Insert a list item into a list.  The item will be inserted in a position\r
@@ -331,7 +363,7 @@ void vListInsert( xList *pxList, xListItem *pxNewListItem );
  * \page vListInsertEnd vListInsertEnd\r
  * \ingroup LinkedList\r
  */\r
-void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );\r
+void vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem );\r
 \r
 /*\r
  * Remove an item from a list.  The list item has a pointer to the list that\r
@@ -339,14 +371,14 @@ void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );
  *\r
  * @param uxListRemove The item to be removed.  The item will remove itself from\r
  * the list pointed to by it's pxContainer parameter.\r
- * \r
+ *\r
  * @return The number of items that remain in the list after the list item has\r
  * been removed.\r
  *\r
  * \page uxListRemove uxListRemove\r
  * \ingroup LinkedList\r
  */\r
-unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove );\r
+unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove );\r
 \r
 #ifdef __cplusplus\r
 }\r
index 1e6a7486d6c955f111198fda86490329065a8542..9dcdcb18ed47dc8bbc5678f4b1689fc602fa1af2 100644 (file)
     ***************************************************************************\r
 \r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
     license and Real Time Engineers Ltd. contact details.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
     fully thread aware and reentrant UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
-    Integrity Systems, who sell the code with commercial support, \r
+    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+    Integrity Systems, who sell the code with commercial support,\r
     indemnification and middleware, under the OpenRTOS brand.\r
-    \r
-    http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
-    engineered and independently SIL3 certified version for use in safety and \r
+\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
     mission critical applications that require provable dependability.\r
 */\r
 \r
@@ -81,7 +81,7 @@
  * PUBLIC LIST API documented in list.h\r
  *----------------------------------------------------------*/\r
 \r
-void vListInitialise( xList *pxList )\r
+void vListInitialise( xList * const pxList )\r
 {\r
        /* The list structure contains a list item which is used to mark the\r
        end of the list.  To initialise the list the list end is inserted\r
@@ -101,16 +101,16 @@ void vListInitialise( xList *pxList )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vListInitialiseItem( xListItem *pxItem )\r
+void vListInitialiseItem( xListItem * const pxItem )\r
 {\r
        /* Make sure the list item is not recorded as being on a list. */\r
        pxItem->pvContainer = NULL;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )\r
+void vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem )\r
 {\r
-volatile xListItem * pxIndex;\r
+xListItem * pxIndex;\r
 \r
        /* Insert a new list item into pxList, but rather than sort the list,\r
        makes the new list item the last item to be removed by a call to\r
@@ -119,8 +119,8 @@ volatile xListItem * pxIndex;
 \r
        pxNewListItem->pxNext = pxIndex;\r
        pxNewListItem->pxPrevious = pxIndex->pxPrevious;\r
-       pxIndex->pxPrevious->pxNext = ( volatile xListItem * ) pxNewListItem;\r
-       pxIndex->pxPrevious = ( volatile xListItem * ) pxNewListItem;   \r
+       pxIndex->pxPrevious->pxNext = pxNewListItem;\r
+       pxIndex->pxPrevious = pxNewListItem;\r
 \r
        /* Remember which list the item is in. */\r
        pxNewListItem->pvContainer = ( void * ) pxList;\r
@@ -129,9 +129,9 @@ volatile xListItem * pxIndex;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vListInsert( xList *pxList, xListItem *pxNewListItem )\r
+void vListInsert( xList * const pxList, xListItem * const pxNewListItem )\r
 {\r
-volatile xListItem *pxIterator;\r
+xListItem *pxIterator;\r
 portTickType xValueOfInsertion;\r
 \r
        /* Insert the new list item into the list, sorted in ulListItem order. */\r
@@ -175,9 +175,9 @@ portTickType xValueOfInsertion;
        }\r
 \r
        pxNewListItem->pxNext = pxIterator->pxNext;\r
-       pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;\r
+       pxNewListItem->pxNext->pxPrevious = pxNewListItem;\r
        pxNewListItem->pxPrevious = pxIterator;\r
-       pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;\r
+       pxIterator->pxNext = pxNewListItem;\r
 \r
        /* Remember which list the item is in.  This allows fast removal of the\r
        item later. */\r
@@ -187,7 +187,7 @@ portTickType xValueOfInsertion;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove )\r
+unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove )\r
 {\r
 xList * pxList;\r
 \r
index a7c30314992be91dc73cac6c0dd615eba96dc9d5..5b24b89156d30c9aa86bd65760103b6b7b5cad7c 100644 (file)
@@ -81,7 +81,7 @@
        #include <intrinsics.h>\r
 \r
        #ifdef __cplusplus\r
-       extern "C" {\r
+               extern "C" {\r
        #endif\r
 \r
        /*-----------------------------------------------------------\r
        #ifdef configASSERT\r
                void vPortValidateInterruptPriority( void );\r
                #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()      vPortValidateInterruptPriority()\r
-#endif\r
+       #endif /* configASSERT */\r
 \r
        #define portNOP() __asm volatile( "NOP" )\r
 \r
 \r
        #ifdef __cplusplus\r
-       }\r
+               } /* extern C */\r
        #endif\r
 \r
+       /* Suppress warnings that are generated by the IAR tools, but cannot be\r
+       fixed in the source code because to do so would cause other compilers to\r
+       generate warnings. */\r
+       #pragma diag_suppress=Pe191\r
+       #pragma diag_suppress=Pa082\r
+\r
 #endif /* __ICCARM__ */\r
 \r
 \r
index 2532aa9ab68820af0b7168fbe48fb9c6bec31d4c..d1e8d5cfcbcd80dab7b67b2034896eccec8a06e4 100644 (file)
@@ -245,9 +245,8 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
 \r
 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )\r
 {\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
 \r
        taskENTER_CRITICAL();\r
@@ -447,9 +446,8 @@ xQueueHandle xReturn = NULL;
        portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )\r
        {\r
        portBASE_TYPE xReturn;\r
-       xQUEUE *pxMutex;\r
+       xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
 \r
-               pxMutex = ( xQUEUE * ) xMutex;\r
                configASSERT( pxMutex );\r
 \r
                /* If this is the task that holds the mutex then pxMutexHolder will not\r
@@ -498,9 +496,8 @@ xQueueHandle xReturn = NULL;
        portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )\r
        {\r
        portBASE_TYPE xReturn;\r
-       xQUEUE *pxMutex;\r
+       xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
 \r
-               pxMutex = ( xQUEUE * ) xMutex;\r
                configASSERT( pxMutex );\r
 \r
                /* Comments regarding mutual exclusion as per those within\r
@@ -565,9 +562,8 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
 {\r
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
        configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
@@ -724,9 +720,8 @@ xQUEUE *pxQueue;
        {\r
        signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
        xTimeOutType xTimeOut;\r
-       xQUEUE *pxQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-               pxQueue = ( xQUEUE * ) xQueue;\r
                configASSERT( pxQueue );\r
                configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -804,9 +799,8 @@ xQUEUE *pxQueue;
        signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
        xTimeOutType xTimeOut;\r
        signed char *pcOriginalReadPosition;\r
-       xQUEUE *pxQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-               pxQueue = ( xQUEUE * ) xQueue;\r
                configASSERT( pxQueue );\r
                configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -825,7 +819,7 @@ xQUEUE *pxQueue;
                                        {\r
                                                traceQUEUE_RECEIVE( pxQueue );\r
 \r
-                                               /* We are actually removing data. */\r
+                                               /* Data is actually being removed (not just peeked). */\r
                                                --( pxQueue->uxMessagesWaiting );\r
 \r
                                                #if ( configUSE_MUTEXES == 1 )\r
@@ -934,9 +928,8 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void *
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
        configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
@@ -1048,9 +1041,8 @@ signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvB
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
 signed char *pcOriginalReadPosition;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -1199,9 +1191,8 @@ signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvB
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -1276,9 +1267,8 @@ signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuff
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 signed char *pcOriginalReadPosition;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -1353,9 +1343,8 @@ unsigned portBASE_TYPE uxReturn;
 \r
 void vQueueDelete( xQueueHandle xQueue )\r
 {\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
-       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
 \r
        traceQUEUE_DELETE( pxQueue );\r
@@ -1645,9 +1634,7 @@ signed portBASE_TYPE xReturn;
        signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
        {\r
        signed portBASE_TYPE xReturn;\r
-       xQUEUE *pxQueue;\r
-\r
-               pxQueue = ( xQUEUE * ) xQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* If the queue is already full we may have to block.  A critical section\r
                is required to prevent an interrupt removing something from the queue\r
@@ -1716,9 +1703,7 @@ signed portBASE_TYPE xReturn;
        signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )\r
        {\r
        signed portBASE_TYPE xReturn;\r
-       xQUEUE *pxQueue;\r
-\r
-               pxQueue = ( xQUEUE * ) xQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* If the queue is already empty we may have to block.  A critical section\r
                is required to prevent an interrupt adding something to the queue\r
@@ -1791,9 +1776,7 @@ signed portBASE_TYPE xReturn;
 \r
        signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
        {\r
-       xQUEUE *pxQueue;\r
-\r
-               pxQueue = ( xQUEUE * ) xQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* Cannot block within an ISR so if there is no space on the queue then\r
                exit without doing anything. */\r
@@ -1826,9 +1809,7 @@ signed portBASE_TYPE xReturn;
        signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
        {\r
        signed portBASE_TYPE xReturn;\r
-       xQUEUE * pxQueue;\r
-\r
-               pxQueue = ( xQUEUE * ) xQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* We cannot block from an ISR, so check there is data available. If\r
                not then just leave without doing anything. */\r
@@ -1917,9 +1898,7 @@ signed portBASE_TYPE xReturn;
 \r
        void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )\r
        {\r
-       xQUEUE *pxQueue;\r
-\r
-               pxQueue = ( xQUEUE * ) xQueue;\r
+       xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* This function should not be called by application code hence the\r
                'Restricted' in its name.  It is not part of the public API.  It is\r
@@ -1999,9 +1978,7 @@ signed portBASE_TYPE xReturn;
        portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
        {\r
        portBASE_TYPE xReturn;\r
-       xQUEUE *pxQueueOrSemaphore;\r
-\r
-               pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
+       xQUEUE * const pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
 \r
                if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\r
                {\r
index 225e61cf085c4528aa42c89571311c4cb9f8de81..5bf1ae7566a7731543985c60f6917e6dcda7d44a 100644 (file)
@@ -201,12 +201,11 @@ PRIVILEGED_DATA static xList xPendingReadyList;                                                   /*< Tasks that have been r
 /* File private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks  = ( unsigned portBASE_TYPE ) 0U;\r
 PRIVILEGED_DATA static volatile portTickType xTickCount                                                = ( portTickType ) 0U;\r
-PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority                                        = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority              = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning                         = pdFALSE;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended            = ( unsigned portBASE_TYPE ) pdFALSE;\r
 PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxPendedTicks                   = ( unsigned portBASE_TYPE ) 0U;\r
-PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending                                            = ( portBASE_TYPE ) pdFALSE;\r
+PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending                                    = ( portBASE_TYPE ) pdFALSE;\r
 PRIVILEGED_DATA static volatile portBASE_TYPE xNumOfOverflows                                  = ( portBASE_TYPE ) 0;\r
 PRIVILEGED_DATA static unsigned portBASE_TYPE uxTaskNumber                                             = ( unsigned portBASE_TYPE ) 0U;\r
 PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime                              = ( portTickType ) portMAX_DELAY;\r
@@ -214,7 +213,7 @@ PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime                           = ( portTic
 #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
 \r
        PRIVILEGED_DATA static unsigned long ulTaskSwitchedInTime = 0UL;        /*< Holds the value of a timer/counter the last time a task was switched in. */\r
-       PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL;                              /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
+       PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL;                      /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
 \r
 #endif\r
 \r
@@ -587,13 +586,6 @@ tskTCB * pxNewTCB;
                                }\r
                        }\r
 \r
-                       /* Remember the top priority to make context switching faster.  Use\r
-                       the priority in pxNewTCB as this has been capped to a valid value. */\r
-                       if( pxNewTCB->uxPriority > uxTopUsedPriority )\r
-                       {\r
-                               uxTopUsedPriority = pxNewTCB->uxPriority;\r
-                       }\r
-\r
                        uxTaskNumber++;\r
 \r
                        #if ( configUSE_TRACE_FACILITY == 1 )\r
@@ -662,7 +654,7 @@ tskTCB * pxNewTCB;
                        }\r
 \r
                        /* Is the task waiting on an event also? */\r
-                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
+                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                        {\r
                                uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
@@ -707,17 +699,21 @@ tskTCB * pxNewTCB;
 \r
                vTaskSuspendAll();\r
                {\r
+                       /* Minor optimisation.  The tick count cannot change in this\r
+                       block. */\r
+                       const portTickType xConstTickCount = xTickCount;\r
+\r
                        /* Generate the tick time at which the task wants to wake. */\r
                        xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;\r
 \r
-                       if( xTickCount < *pxPreviousWakeTime )\r
+                       if( xConstTickCount < *pxPreviousWakeTime )\r
                        {\r
                                /* The tick count has overflowed since this function was\r
                                lasted called.  In this case the only time we should ever\r
                                actually delay is if the wake time has also     overflowed,\r
                                and the wake time is greater than the tick time.  When this\r
                                is the case it is as if neither time had overflowed. */\r
-                               if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xTickCount ) )\r
+                               if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )\r
                                {\r
                                        xShouldDelay = pdTRUE;\r
                                }\r
@@ -727,7 +723,7 @@ tskTCB * pxNewTCB;
                                /* The tick time has not overflowed.  In this case we will\r
                                delay if either the wake time has overflowed, and/or the\r
                                tick time is less than the wake time. */\r
-                               if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xTickCount ) )\r
+                               if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )\r
                                {\r
                                        xShouldDelay = pdTRUE;\r
                                }\r
@@ -825,9 +821,7 @@ tskTCB * pxNewTCB;
        {\r
        eTaskState eReturn;\r
        xList *pxStateList;\r
-       tskTCB *pxTCB;\r
-\r
-               pxTCB = ( tskTCB * ) xTask;\r
+       const tskTCB * const pxTCB = ( tskTCB * ) xTask;\r
 \r
                if( pxTCB == pxCurrentTCB )\r
                {\r
@@ -1048,7 +1042,7 @@ tskTCB * pxNewTCB;
                        }\r
 \r
                        /* Is the task waiting on an event also? */\r
-                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
+                       if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
                        {\r
                                uxListRemove( &( pxTCB->xEventListItem ) );\r
                        }\r
@@ -1126,15 +1120,11 @@ tskTCB * pxNewTCB;
 \r
        void vTaskResume( xTaskHandle xTaskToResume )\r
        {\r
-       tskTCB *pxTCB;\r
+       tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
 \r
                /* It does not make sense to resume the calling task. */\r
                configASSERT( xTaskToResume );\r
 \r
-               /* Remove the task from whichever list it is currently in, and place\r
-               it in the ready list. */\r
-               pxTCB = ( tskTCB * ) xTaskToResume;\r
-\r
                /* The parameter cannot be NULL as it is impossible to resume the\r
                currently executing task. */\r
                if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
@@ -1172,31 +1162,29 @@ tskTCB * pxNewTCB;
        portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume )\r
        {\r
        portBASE_TYPE xYieldRequired = pdFALSE;\r
-       tskTCB *pxTCB;\r
+       tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
        unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
                configASSERT( xTaskToResume );\r
 \r
-               /* RTOS ports that support interrupt nesting have the concept of a \r
-               maximum system call (or maximum API call) interrupt priority.  \r
-               Interrupts that are     above the maximum system call priority are keep \r
-               permanently enabled, even when the RTOS kernel is in a critical section, \r
-               but cannot make any calls to FreeRTOS API functions.  If configASSERT() \r
-               is defined in FreeRTOSConfig.h then \r
+               /* RTOS ports that support interrupt nesting have the concept of a\r
+               maximum system call (or maximum API call) interrupt priority.\r
+               Interrupts that are     above the maximum system call priority are keep\r
+               permanently enabled, even when the RTOS kernel is in a critical section,\r
+               but cannot make any calls to FreeRTOS API functions.  If configASSERT()\r
+               is defined in FreeRTOSConfig.h then\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
-               failure if a FreeRTOS API function is called from an interrupt that has \r
-               been assigned a priority above the configured maximum system call \r
-               priority.  Only FreeRTOS functions that end in FromISR can be called \r
-               from interrupts that have been assigned a priority at or (logically) \r
-               below the maximum system call interrupt priority.  FreeRTOS maintains a \r
-               separate interrupt safe API to ensure interrupt entry is as fast and as \r
-               simple as possible.  More information (albeit Cortex-M specific) is \r
-               provided on the following link: \r
+               failure if a FreeRTOS API function is called from an interrupt that has\r
+               been assigned a priority above the configured maximum system call\r
+               priority.  Only FreeRTOS functions that end in FromISR can be called\r
+               from interrupts that have been assigned a priority at or (logically)\r
+               below the maximum system call interrupt priority.  FreeRTOS maintains a\r
+               separate interrupt safe API to ensure interrupt entry is as fast and as\r
+               simple as possible.  More information (albeit Cortex-M specific) is\r
+               provided on the following link:\r
                http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
                portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
-               pxTCB = ( tskTCB * ) xTaskToResume;\r
-\r
                uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
                        if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
@@ -1434,20 +1422,20 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
-       above the maximum system call priority are keep permanently enabled, even \r
+       above the maximum system call priority are keep permanently enabled, even\r
        when the RTOS kernel is in a critical section, but cannot make any calls to\r
-       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h \r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
        then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
        failure if a FreeRTOS API function is called from an interrupt that has been\r
        assigned a priority above the configured maximum system call priority.\r
        Only FreeRTOS functions that end in FromISR can be called from interrupts\r
-       that have been assigned a priority at or (logically) below the maximum \r
-       system call     interrupt priority.  FreeRTOS maintains a separate interrupt \r
-       safe API to ensure interrupt entry is as fast and as simple as possible.  \r
-       More information (albeit Cortex-M specific) is provided on the following \r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
        link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
-       \r
+\r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        xReturn = xTickCount;\r
        portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
@@ -1506,7 +1494,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if( INCLUDE_vTaskDelete == 1 )\r
                                {\r
-                                       /* Fill in an xTaskStatusType structure with information on \r
+                                       /* Fill in an xTaskStatusType structure with information on\r
                                        each task that has been deleted but not yet cleaned up. */\r
                                        uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );\r
                                }\r
@@ -1514,7 +1502,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if ( INCLUDE_vTaskSuspend == 1 )\r
                                {\r
-                                       /* Fill in an xTaskStatusType structure with information on \r
+                                       /* Fill in an xTaskStatusType structure with information on\r
                                        each task in the Suspended state. */\r
                                        uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );\r
                                }\r
@@ -1522,11 +1510,17 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 \r
                                #if ( configGENERATE_RUN_TIME_STATS == 1)\r
                                {\r
-                                       *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+                                       if( pulTotalRunTime != NULL )\r
+                                       {\r
+                                               *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+                                       }\r
                                }\r
                                #else\r
                                {\r
-                                       *pulTotalRunTime = 0;\r
+                                       if( pulTotalRunTime != NULL )\r
+                                       {\r
+                                               *pulTotalRunTime = 0;\r
+                                       }\r
                                }\r
                                #endif\r
                        }\r
@@ -1585,75 +1579,82 @@ portBASE_TYPE xSwitchRequired = pdFALSE;
                /* Increment the RTOS tick, switching the delayed and overflowed\r
                delayed lists if it wraps to 0. */\r
                ++xTickCount;\r
-               if( xTickCount == ( portTickType ) 0U )\r
-               {\r
-                       taskSWITCH_DELAYED_LISTS();\r
-               }\r
 \r
-               /* See if this tick has made a timeout expire.  Tasks are stored in the\r
-               queue in the order of their wake time - meaning once one tasks has been\r
-               found whose block time has not expired there is no need not look any\r
-               further down the list. */\r
-               if( xTickCount >= xNextTaskUnblockTime )\r
                {\r
-                       for( ;; )\r
+                       /* Minor optimisation.  The tick count cannot change in this\r
+                       block. */\r
+                       const portTickType xConstTickCount = xTickCount;\r
+\r
+                       if( xConstTickCount == ( portTickType ) 0U )\r
                        {\r
-                               if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
-                               {\r
-                                       /* The delayed list is empty.  Set xNextTaskUnblockTime to\r
-                                       the     maximum possible value so it is extremely unlikely that\r
-                                       the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
-                                       next time through. */\r
-                                       xNextTaskUnblockTime = portMAX_DELAY;\r
-                                       break;\r
-                               }\r
-                               else\r
+                               taskSWITCH_DELAYED_LISTS();\r
+                       }\r
+\r
+                       /* See if this tick has made a timeout expire.  Tasks are stored in the\r
+                       queue in the order of their wake time - meaning once one tasks has been\r
+                       found whose block time has not expired there is no need not look any\r
+                       further down the list. */\r
+                       if( xConstTickCount >= xNextTaskUnblockTime )\r
+                       {\r
+                               for( ;; )\r
                                {\r
-                                       /* The delayed list is not empty, get the value of the item\r
-                                       at the head of the delayed list.  This is the time at which\r
-                                       the task at the head of the delayed list must be removed\r
-                                       from the Blocked state. */\r
-                                       pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
-                                       xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
-\r
-                                       if( xTickCount < xItemValue )\r
+                                       if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
                                        {\r
-                                               /* It is not time to unblock this item yet, but the item\r
-                                               value is the time at which the task at the head of the\r
-                                               blocked list must be removed from the Blocked state -\r
-                                               so record the item value in xNextTaskUnblockTime. */\r
-                                               xNextTaskUnblockTime = xItemValue;\r
+                                               /* The delayed list is empty.  Set xNextTaskUnblockTime to\r
+                                               the     maximum possible value so it is extremely unlikely that\r
+                                               the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
+                                               next time through. */\r
+                                               xNextTaskUnblockTime = portMAX_DELAY;\r
                                                break;\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               /* The delayed list is not empty, get the value of the item\r
+                                               at the head of the delayed list.  This is the time at which\r
+                                               the task at the head of the delayed list must be removed\r
+                                               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 item\r
+                                                       value is the time at which the task at the head of the\r
+                                                       blocked list must be removed from the Blocked state -\r
+                                                       so record the item value in xNextTaskUnblockTime. */\r
+                                                       xNextTaskUnblockTime = xItemValue;\r
+                                                       break;\r
+                                               }\r
 \r
-                                       /* It is time to remove the item from the Blocked state. */\r
-                                       uxListRemove( &( pxTCB->xGenericListItem ) );\r
+                                               /* It is time to remove the item from the Blocked state. */\r
+                                               uxListRemove( &( pxTCB->xGenericListItem ) );\r
 \r
-                                       /* Is the task waiting on an event also?  If so remove it\r
-                                       from the event list. */\r
-                                       if( pxTCB->xEventListItem.pvContainer != NULL )\r
-                                       {\r
-                                               uxListRemove( &( pxTCB->xEventListItem ) );\r
-                                       }\r
+                                               /* Is the task waiting on an event also?  If so remove it\r
+                                               from the event list. */\r
+                                               if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+                                               {\r
+                                                       uxListRemove( &( pxTCB->xEventListItem ) );\r
+                                               }\r
 \r
-                                       /* Place the unblocked task into the appropriate ready\r
-                                       list. */\r
-                                       prvAddTaskToReadyList( pxTCB );\r
+                                               /* Place the unblocked task into the appropriate ready\r
+                                               list. */\r
+                                               prvAddTaskToReadyList( pxTCB );\r
 \r
-                                       /* A task being unblocked cannot cause an immediate context\r
-                                       switch if preemption is turned off. */\r
-                                       #if (  configUSE_PREEMPTION == 1 )\r
-                                       {\r
-                                               /* Preemption is on, but a context switch should only\r
-                                               be performed if the unblocked task has a priority that\r
-                                               is equal to or higher than the currently executing\r
-                                               task. */\r
-                                               if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+                                               /* A task being unblocked cannot cause an immediate context\r
+                                               switch if preemption is turned off. */\r
+                                               #if (  configUSE_PREEMPTION == 1 )\r
                                                {\r
-                                                       xSwitchRequired = pdTRUE;\r
+                                                       /* Preemption is on, but a context switch should only\r
+                                                       be performed if the unblocked task has a priority that\r
+                                                       is equal to or higher than the currently executing\r
+                                                       task. */\r
+                                                       if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+                                                       {\r
+                                                               xSwitchRequired = pdTRUE;\r
+                                                       }\r
                                                }\r
+                                               #endif /* configUSE_PREEMPTION */\r
                                        }\r
-                                       #endif /* configUSE_PREEMPTION */\r
                                }\r
                        }\r
                }\r
@@ -1999,6 +2000,9 @@ portBASE_TYPE xReturn;
 \r
        taskENTER_CRITICAL();\r
        {\r
+               /* Minor optimisation.  The tick count cannot change in this block. */\r
+               const portTickType xConstTickCount = xTickCount;\r
+\r
                #if ( INCLUDE_vTaskSuspend == 1 )\r
                        /* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is\r
                        the maximum block time then the task should block indefinitely, and\r
@@ -2010,7 +2014,7 @@ portBASE_TYPE xReturn;
                        else /* We are not blocking indefinitely, perform the checks below. */\r
                #endif\r
 \r
-               if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
+               if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xConstTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
                {\r
                        /* The tick count is greater than the time at which vTaskSetTimeout()\r
                        was called, but has also overflowed since vTaskSetTimeOut() was called.\r
@@ -2018,10 +2022,10 @@ portBASE_TYPE xReturn;
                        passed since vTaskSetTimeout() was called. */\r
                        xReturn = pdTRUE;\r
                }\r
-               else if( ( ( portTickType ) ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
+               else if( ( ( portTickType ) ( ( portTickType ) xConstTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
                {\r
                        /* Not a genuine timeout. Adjust parameters for time remaining. */\r
-                       *pxTicksToWait -= ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
+                       *pxTicksToWait -= ( ( portTickType ) xConstTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
                        vTaskSetTimeOutState( pxTimeOut );\r
                        xReturn = pdFALSE;\r
                }\r
@@ -2458,10 +2462,10 @@ tskTCB *pxNewTCB;
        unsigned portBASE_TYPE uxTask = 0;\r
 \r
                if( listCURRENT_LIST_LENGTH( pxList ) > 0 )\r
-               {                       \r
+               {\r
                        listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
-                       \r
-                       /* Populate an xTaskStatusType structure within the \r
+\r
+                       /* Populate an xTaskStatusType structure within the\r
                        pxTaskStatusArray array for each task that is referenced from\r
                        pxList.  See the definition of xTaskStatusType in task.h for the\r
                        meaning of each xTaskStatusType structure member. */\r
@@ -2741,7 +2745,6 @@ tskTCB *pxNewTCB;
        {\r
        xTaskStatusType *pxTaskStatusArray;\r
        volatile unsigned portBASE_TYPE uxArraySize, x;\r
-       unsigned long ulTotalRunTime;\r
        char cStatus;\r
 \r
                /*\r
@@ -2782,7 +2785,7 @@ tskTCB *pxNewTCB;
                if( pxTaskStatusArray != NULL )\r
                {\r
                        /* Generate the (binary) data. */\r
-                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\r
 \r
                        /* Create a human readable table from the binary data. */\r
                        for( x = 0; x < uxArraySize; x++ )\r
@@ -2825,7 +2828,7 @@ tskTCB *pxNewTCB;
        {\r
        xTaskStatusType *pxTaskStatusArray;\r
        volatile unsigned portBASE_TYPE uxArraySize, x;\r
-       unsigned long ulTotalRunTime, ulStatsAsPercentage;\r
+       unsigned long ulTotalTime, ulStatsAsPercentage;\r
 \r
                /*\r
                 * PLEASE NOTE:\r
@@ -2865,13 +2868,13 @@ tskTCB *pxNewTCB;
                if( pxTaskStatusArray != NULL )\r
                {\r
                        /* Generate the (binary) data. */\r
-                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+                       uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\r
 \r
                        /* For percentage calculations. */\r
-                       ulTotalRunTime /= 100UL;\r
+                       ulTotalTime /= 100UL;\r
 \r
                        /* Avoid divide by zero errors. */\r
-                       if( ulTotalRunTime > 0 )\r
+                       if( ulTotalTime > 0 )\r
                        {\r
                                /* Create a human readable table from the binary data. */\r
                                for( x = 0; x < uxArraySize; x++ )\r
@@ -2879,7 +2882,7 @@ tskTCB *pxNewTCB;
                                        /* What percentage of the total run time has the task used?\r
                                        This will always be rounded down to the nearest integer.\r
                                        ulTotalRunTimeDiv100 has already been divided by 100. */\r
-                                       ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;\r
+                                       ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
 \r
                                        if( ulStatsAsPercentage > 0UL )\r
                                        {\r