From 2d0dfbe32e1d3ee41f64f6a29261122e946e7b2b Mon Sep 17 00:00:00 2001 From: richardbarry Date: Sun, 18 Nov 2012 09:13:39 +0000 Subject: [PATCH] Move the call that sets xTimeNow inside the loop that drains the timer queue to ensure higher priority tasks that pre-empt the timer daemon cannot post messages that appear to be in the future to the daemon task. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1812 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Source/timers.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/FreeRTOS/Source/timers.c b/FreeRTOS/Source/timers.c index e68cc0341..bc4ef062d 100644 --- a/FreeRTOS/Source/timers.c +++ b/FreeRTOS/Source/timers.c @@ -512,10 +512,6 @@ xTIMER *pxTimer; portBASE_TYPE xTimerListsWereSwitched, xResult; portTickType xTimeNow; - /* In this case the xTimerListsWereSwitched parameter is not used, but it - must be present in the function call. */ - xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); - while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) { pxTimer = xMessage.pxTimer; @@ -528,6 +524,14 @@ portTickType xTimeNow; traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue ); + /* In this case the xTimerListsWereSwitched parameter is not used, but + it must be present in the function call. prvSampleTimeNow() must be + called after the message is received from xTimerQueue so there is no + possibility of a higher priority task adding a message to the message + queue with a time that is ahead of the timer daemon task (because it + pre-empted the timer daemon task after the xTimeNow value was set). */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + switch( xMessage.xMessageID ) { case tmrCOMMAND_START : @@ -680,3 +684,6 @@ xTIMER *pxTimer = ( xTIMER * ) xTimer; to include software timer functionality. If you want to include software timer functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ #endif /* configUSE_TIMERS == 1 */ + + + -- 2.39.5