]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Re-implement the LPC18xx and SmartFusion2 run time stats implementation to use the...
[freertos] / FreeRTOS / Source / tasks.c
index 91358b8a9dca02309585b3d7edf62da345759dac..abe3440669f520683c879371478bbbc4790223e3 100644 (file)
@@ -1843,12 +1843,17 @@ void vTaskSwitchContext( void )
                                        ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
                                #endif\r
 \r
-                               /* Add the amount of time the task has been running to the accumulated\r
-                               time so far.  The time the task started running was stored in\r
-                               ulTaskSwitchedInTime.  Note that there is no overflow protection here\r
-                               so count values are only valid until the timer overflows.  Generally\r
-                               this will be about 1 hour assuming a 1uS timer increment. */\r
-                               pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
+                               /* Add the amount of time the task has been running to the \r
+                               accumulated     time so far.  The time the task started running was \r
+                               stored in ulTaskSwitchedInTime.  Note that there is no overflow \r
+                               protection here so count values are only valid until the timer \r
+                               overflows.  The guard against negative values is to protect\r
+                               against suspect run time stat counter implementations - which\r
+                               are provided by the application, not the kernel. */\r
+                               if( ulTotalRunTime > ulTaskSwitchedInTime )\r
+                               {\r
+                                       pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
+                               }\r
                                ulTaskSwitchedInTime = ulTotalRunTime;\r
                }\r
                #endif /* configGENERATE_RUN_TIME_STATS */\r