summaryrefslogtreecommitdiff
path: root/FreeRTOS/Source/tasks.c
diff options
context:
space:
mode:
Diffstat (limited to 'FreeRTOS/Source/tasks.c')
-rw-r--r--FreeRTOS/Source/tasks.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c
index 91358b8a9..abe344066 100644
--- a/FreeRTOS/Source/tasks.c
+++ b/FreeRTOS/Source/tasks.c
@@ -1843,12 +1843,17 @@ void vTaskSwitchContext( void )
ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();
#endif
- /* Add the amount of time the task has been running to the accumulated
- time so far. The time the task started running was stored in
- ulTaskSwitchedInTime. Note that there is no overflow protection here
- so count values are only valid until the timer overflows. Generally
- this will be about 1 hour assuming a 1uS timer increment. */
- pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );
+ /* Add the amount of time the task has been running to the
+ accumulated time so far. The time the task started running was
+ stored in ulTaskSwitchedInTime. Note that there is no overflow
+ protection here so count values are only valid until the timer
+ overflows. The guard against negative values is to protect
+ against suspect run time stat counter implementations - which
+ are provided by the application, not the kernel. */
+ if( ulTotalRunTime > ulTaskSwitchedInTime )
+ {
+ pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );
+ }
ulTaskSwitchedInTime = ulTotalRunTime;
}
#endif /* configGENERATE_RUN_TIME_STATS */