Skip to content

Commit 271bdfb

Browse files
authored
Simplify prvInitialiseNewTask() (#417)
Memset newly allocated TCB structures to zero, and remove code that set individual structure members to zero.
1 parent e13f990 commit 271bdfb

File tree

1 file changed

+9
-45
lines changed

1 file changed

+9
-45
lines changed

tasks.c

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
602602
/* The memory used for the task's TCB and stack are passed into this
603603
* function - use them. */
604604
pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
605+
memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
605606
pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
606607

607608
#if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
@@ -643,6 +644,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
643644
* on the implementation of the port malloc function and whether or
644645
* not static allocation is being used. */
645646
pxNewTCB = ( TCB_t * ) pxTaskDefinition->pxTaskBuffer;
647+
memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
646648

647649
/* Store the stack location in the TCB. */
648650
pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;
@@ -692,6 +694,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
692694

693695
if( pxNewTCB != NULL )
694696
{
697+
memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
698+
695699
/* Store the stack location in the TCB. */
696700
pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;
697701

@@ -747,6 +751,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
747751

748752
if( pxNewTCB != NULL )
749753
{
754+
memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
755+
750756
/* Allocate space for the stack used by the task being created.
751757
* The base of the stack memory stored in the TCB so the task can
752758
* be deleted later if required. */
@@ -774,6 +780,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
774780

775781
if( pxNewTCB != NULL )
776782
{
783+
memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
784+
777785
/* Store the stack location in the TCB. */
778786
pxNewTCB->pxStack = pxStack;
779787
}
@@ -910,9 +918,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
910918
}
911919
else
912920
{
913-
/* The task has not been given a name, so just ensure there is a NULL
914-
* terminator when it is read out. */
915-
pxNewTCB->pcTaskName[ 0 ] = 0x00;
921+
mtCOVERAGE_TEST_MARKER();
916922
}
917923

918924
/* This is used as an array index so must ensure it's not too large. */
@@ -931,7 +937,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
931937
#if ( configUSE_MUTEXES == 1 )
932938
{
933939
pxNewTCB->uxBasePriority = uxPriority;
934-
pxNewTCB->uxMutexesHeld = 0;
935940
}
936941
#endif /* configUSE_MUTEXES */
937942

@@ -946,24 +951,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
946951
listSET_LIST_ITEM_VALUE( &( pxNewTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
947952
listSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB );
948953

949-
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
950-
{
951-
pxNewTCB->uxCriticalNesting = ( UBaseType_t ) 0U;
952-
}
953-
#endif /* portCRITICAL_NESTING_IN_TCB */
954-
955-
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
956-
{
957-
pxNewTCB->pxTaskTag = NULL;
958-
}
959-
#endif /* configUSE_APPLICATION_TASK_TAG */
960-
961-
#if ( configGENERATE_RUN_TIME_STATS == 1 )
962-
{
963-
pxNewTCB->ulRunTimeCounter = ( configRUN_TIME_COUNTER_TYPE ) 0;
964-
}
965-
#endif /* configGENERATE_RUN_TIME_STATS */
966-
967954
#if ( portUSING_MPU_WRAPPERS == 1 )
968955
{
969956
vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth );
@@ -975,19 +962,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
975962
}
976963
#endif
977964

978-
#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
979-
{
980-
memset( ( void * ) &( pxNewTCB->pvThreadLocalStoragePointers[ 0 ] ), 0x00, sizeof( pxNewTCB->pvThreadLocalStoragePointers ) );
981-
}
982-
#endif
983-
984-
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
985-
{
986-
memset( ( void * ) &( pxNewTCB->ulNotifiedValue[ 0 ] ), 0x00, sizeof( pxNewTCB->ulNotifiedValue ) );
987-
memset( ( void * ) &( pxNewTCB->ucNotifyState[ 0 ] ), 0x00, sizeof( pxNewTCB->ucNotifyState ) );
988-
}
989-
#endif
990-
991965
#if ( configUSE_NEWLIB_REENTRANT == 1 )
992966
{
993967
/* Initialise this task's Newlib reent structure.
@@ -997,12 +971,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
997971
}
998972
#endif
999973

1000-
#if ( INCLUDE_xTaskAbortDelay == 1 )
1001-
{
1002-
pxNewTCB->ucDelayAborted = pdFALSE;
1003-
}
1004-
#endif
1005-
1006974
/* Initialize the TCB stack to look as if the task was already running,
1007975
* but had been interrupted by the scheduler. The return address is set
1008976
* to the start of the task function. Once the stack has been initialised
@@ -1122,10 +1090,6 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
11221090
{
11231091
/* Add a counter into the TCB for tracing only. */
11241092
pxNewTCB->uxTCBNumber = uxTaskNumber;
1125-
1126-
/* Initialize the uxTaskNumber member to zero. It is utilized by the
1127-
* application using vTaskSetTaskNumber and uxTaskGetTaskNumber APIs. */
1128-
pxNewTCB->uxTaskNumber = 0;
11291093
}
11301094
#endif /* configUSE_TRACE_FACILITY */
11311095
traceTASK_CREATE( pxNewTCB );

0 commit comments

Comments
 (0)