mirror of
				https://github.com/FreeRTOS/FreeRTOS-Kernel.git
				synced 2025-11-04 11:09:01 +01:00 
			
		
		
		
	Simplify prvInitialiseNewTask() (#417)
Memset newly allocated TCB structures to zero, and remove code that set individual structure members to zero.
This commit is contained in:
		
							parent
							
								
									e13f990385
								
							
						
					
					
						commit
						271bdfb880
					
				
							
								
								
									
										54
									
								
								tasks.c
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								tasks.c
									
									
									
									
									
								
							@ -602,6 +602,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
 | 
			
		||||
            /* The memory used for the task's TCB and stack are passed into this
 | 
			
		||||
             * function - use them. */
 | 
			
		||||
            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. */
 | 
			
		||||
            memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
 | 
			
		||||
            pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer;
 | 
			
		||||
 | 
			
		||||
            #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;
 | 
			
		||||
             * on the implementation of the port malloc function and whether or
 | 
			
		||||
             * not static allocation is being used. */
 | 
			
		||||
            pxNewTCB = ( TCB_t * ) pxTaskDefinition->pxTaskBuffer;
 | 
			
		||||
            memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
 | 
			
		||||
 | 
			
		||||
            /* Store the stack location in the TCB. */
 | 
			
		||||
            pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;
 | 
			
		||||
@ -692,6 +694,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
 | 
			
		||||
 | 
			
		||||
            if( pxNewTCB != NULL )
 | 
			
		||||
            {
 | 
			
		||||
                memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
 | 
			
		||||
 | 
			
		||||
                /* Store the stack location in the TCB. */
 | 
			
		||||
                pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;
 | 
			
		||||
 | 
			
		||||
@ -747,6 +751,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
 | 
			
		||||
 | 
			
		||||
                if( pxNewTCB != NULL )
 | 
			
		||||
                {
 | 
			
		||||
                    memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
 | 
			
		||||
 | 
			
		||||
                    /* Allocate space for the stack used by the task being created.
 | 
			
		||||
                     * The base of the stack memory stored in the TCB so the task can
 | 
			
		||||
                     * be deleted later if required. */
 | 
			
		||||
@ -774,6 +780,8 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
 | 
			
		||||
 | 
			
		||||
                    if( pxNewTCB != NULL )
 | 
			
		||||
                    {
 | 
			
		||||
                        memset( ( void * ) pxNewTCB, 0x00, sizeof( TCB_t ) );
 | 
			
		||||
 | 
			
		||||
                        /* Store the stack location in the TCB. */
 | 
			
		||||
                        pxNewTCB->pxStack = pxStack;
 | 
			
		||||
                    }
 | 
			
		||||
@ -910,9 +918,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        /* The task has not been given a name, so just ensure there is a NULL
 | 
			
		||||
         * terminator when it is read out. */
 | 
			
		||||
        pxNewTCB->pcTaskName[ 0 ] = 0x00;
 | 
			
		||||
        mtCOVERAGE_TEST_MARKER();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* 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,
 | 
			
		||||
    #if ( configUSE_MUTEXES == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            pxNewTCB->uxBasePriority = uxPriority;
 | 
			
		||||
            pxNewTCB->uxMutexesHeld = 0;
 | 
			
		||||
        }
 | 
			
		||||
    #endif /* configUSE_MUTEXES */
 | 
			
		||||
 | 
			
		||||
@ -946,24 +951,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
 | 
			
		||||
    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. */
 | 
			
		||||
    listSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB );
 | 
			
		||||
 | 
			
		||||
    #if ( portCRITICAL_NESTING_IN_TCB == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            pxNewTCB->uxCriticalNesting = ( UBaseType_t ) 0U;
 | 
			
		||||
        }
 | 
			
		||||
    #endif /* portCRITICAL_NESTING_IN_TCB */
 | 
			
		||||
 | 
			
		||||
    #if ( configUSE_APPLICATION_TASK_TAG == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            pxNewTCB->pxTaskTag = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    #endif /* configUSE_APPLICATION_TASK_TAG */
 | 
			
		||||
 | 
			
		||||
    #if ( configGENERATE_RUN_TIME_STATS == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            pxNewTCB->ulRunTimeCounter = ( configRUN_TIME_COUNTER_TYPE ) 0;
 | 
			
		||||
        }
 | 
			
		||||
    #endif /* configGENERATE_RUN_TIME_STATS */
 | 
			
		||||
 | 
			
		||||
    #if ( portUSING_MPU_WRAPPERS == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth );
 | 
			
		||||
@ -975,19 +962,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
 | 
			
		||||
        {
 | 
			
		||||
            memset( ( void * ) &( pxNewTCB->pvThreadLocalStoragePointers[ 0 ] ), 0x00, sizeof( pxNewTCB->pvThreadLocalStoragePointers ) );
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ( configUSE_TASK_NOTIFICATIONS == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            memset( ( void * ) &( pxNewTCB->ulNotifiedValue[ 0 ] ), 0x00, sizeof( pxNewTCB->ulNotifiedValue ) );
 | 
			
		||||
            memset( ( void * ) &( pxNewTCB->ucNotifyState[ 0 ] ), 0x00, sizeof( pxNewTCB->ucNotifyState ) );
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ( configUSE_NEWLIB_REENTRANT == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            /* Initialise this task's Newlib reent structure.
 | 
			
		||||
@ -997,12 +971,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if ( INCLUDE_xTaskAbortDelay == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            pxNewTCB->ucDelayAborted = pdFALSE;
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    /* Initialize the TCB stack to look as if the task was already running,
 | 
			
		||||
     * but had been interrupted by the scheduler.  The return address is set
 | 
			
		||||
     * to the start of the task function. Once the stack has been initialised
 | 
			
		||||
@ -1122,10 +1090,6 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
 | 
			
		||||
            {
 | 
			
		||||
                /* Add a counter into the TCB for tracing only. */
 | 
			
		||||
                pxNewTCB->uxTCBNumber = uxTaskNumber;
 | 
			
		||||
 | 
			
		||||
                /* Initialize the uxTaskNumber member to zero. It is utilized by the
 | 
			
		||||
                 * application using vTaskSetTaskNumber and uxTaskGetTaskNumber APIs. */
 | 
			
		||||
                pxNewTCB->uxTaskNumber = 0;
 | 
			
		||||
            }
 | 
			
		||||
        #endif /* configUSE_TRACE_FACILITY */
 | 
			
		||||
        traceTASK_CREATE( pxNewTCB );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user