Introduce prvResetNextTaskUnblockTime() to encapsulate functionality from various places in the code into a single function.

This commit is contained in:
Richard Barry 2013-12-13 10:35:11 +00:00
parent acad916453
commit c17c65fc09

View File

@ -339,25 +339,7 @@ count overflows. */
pxDelayedTaskList = pxOverflowDelayedTaskList; \ pxDelayedTaskList = pxOverflowDelayedTaskList; \
pxOverflowDelayedTaskList = pxTemp; \ pxOverflowDelayedTaskList = pxTemp; \
xNumOfOverflows++; \ xNumOfOverflows++; \
\ prvResetNextTaskUnblockTime(); \
if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) \
{ \
/* The new current delayed list is empty. Set \
xNextTaskUnblockTime to the maximum possible value so it is \
extremely unlikely that the \
if( xTickCount >= xNextTaskUnblockTime ) test will pass until \
there is an item in the delayed list. */ \
xNextTaskUnblockTime = portMAX_DELAY; \
} \
else \
{ \
/* The new current delayed list is not empty, get the value of \
the item at the head of the delayed list. This is the time at \
which the task at the head of the delayed list should be removed \
from the Blocked state. */ \
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); \
xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) ); \
} \
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -483,6 +465,14 @@ static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TY
#endif #endif
/*
* Set xNextTaskUnblockTime to the time at which the next Blocked state task
* will exit the Blocked state.
*/
static void prvResetNextTaskUnblockTime( void );
/*-----------------------------------------------------------*/
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 ) 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 )
{ {
signed portBASE_TYPE xReturn; signed portBASE_TYPE xReturn;
@ -697,10 +687,9 @@ tskTCB * pxNewTCB;
} }
else else
{ {
/* Reset the next expected unblock time in case it referred to the task /* Reset the next expected unblock time in case it referred to
that has just been deleted. */ the task that has just been deleted. */
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); prvResetNextTaskUnblockTime();
xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );
} }
} }
} }
@ -1124,11 +1113,10 @@ tskTCB * pxNewTCB;
{ {
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
{ {
/* A task other than the currently running task was suspended, reset /* A task other than the currently running task was suspended,
the next expected unblock time in case it referred to the task that reset the next expected unblock time in case it referred to the
is now in the Suspended state. */ task that is now in the Suspended state. */
pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); prvResetNextTaskUnblockTime();
xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );
} }
} }
} }
@ -2782,6 +2770,31 @@ tskTCB *pxNewTCB;
#endif /* INCLUDE_vTaskDelete */ #endif /* INCLUDE_vTaskDelete */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvResetNextTaskUnblockTime( void )
{
tskTCB *pxTCB;
if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )
{
/* The new current delayed list is empty. Set
xNextTaskUnblockTime to the maximum possible value so it is
extremely unlikely that the
if( xTickCount >= xNextTaskUnblockTime ) test will pass until
there is an item in the delayed list. */
xNextTaskUnblockTime = portMAX_DELAY;
}
else
{
/* The new current delayed list is not empty, get the value of
the item at the head of the delayed list. This is the time at
which the task at the head of the delayed list should be removed
from the Blocked state. */
( pxTCB ) = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );
xNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xGenericListItem ) );
}
}
/*-----------------------------------------------------------*/
#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )
xTaskHandle xTaskGetCurrentTaskHandle( void ) xTaskHandle xTaskGetCurrentTaskHandle( void )