We do not need all the checks if we have a valid indentifier to a thread class object.
Using the new _Thread_Get_objects_information() instead of the inline function _Thread_Get_objects_information_by_id() avoids dead code since the identifier in a thread control is always valid and the return NULL path in _Thread_Get_objects_information_by_id() would be dead code. The _Thread_Get_objects_information_by_id() should be an inline function since it is used by _Thread_Get() and thus performance critical. Static analyzers which cannot derive that the identifier in a thread control is always valid, may find a potential NULL pointer access (or otherwise find dead code). The identifier in an object control is always valid, see _Objects_Initialize_information() and _Objects_Extend_information(). Move _RTEMS_tasks_Free() to the only source file which calls this function. --- cpukit/include/rtems/rtems/tasksimpl.h | 16 ---------------- cpukit/include/rtems/score/threadimpl.h | 24 ++++++++++++++++++++++++ cpukit/rtems/src/taskconstruct.c | 8 ++++++++ cpukit/score/src/threadrestart.c | 12 ++++++------ 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/cpukit/include/rtems/rtems/tasksimpl.h b/cpukit/include/rtems/rtems/tasksimpl.h index eac4647897..62a618b635 100644 --- a/cpukit/include/rtems/rtems/tasksimpl.h +++ b/cpukit/include/rtems/rtems/tasksimpl.h @@ -66,22 +66,6 @@ RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate(void) _Objects_Allocate_unprotected( &_RTEMS_tasks_Information.Objects ); } -/** - * @brief Frees a task control block. - * - * This routine frees a task control block to the - * inactive chain of free task control blocks. - */ -RTEMS_INLINE_ROUTINE void _RTEMS_tasks_Free ( - Thread_Control *the_task -) -{ - _Objects_Free( - _Objects_Get_information_id( the_task->Object.id ), - &the_task->Object - ); -} - /** * @brief Converts the RTEMS API priority to the corresponding SuperCore * priority and validates it. diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index d5381c9871..e76f9c3972 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -846,6 +846,30 @@ RTEMS_INLINE_ROUTINE Objects_Information *_Thread_Get_objects_information_by_id( return _Objects_Information_table[ the_api ][ 1 ]; } +/** + * @brief Gets the thread object information of the thread. + * + * @param the_thread is the thread to get the thread object information. + * + * @return Returns the thread object information of the thread. + */ +RTEMS_INLINE_ROUTINE Thread_Information *_Thread_Get_objects_information( + Thread_Control *the_thread +) +{ + size_t the_api; + Thread_Information *information; + + the_api = (size_t) _Objects_Get_API( the_thread->Object.id ); + _Assert( _Objects_Is_api_valid( the_api ) ); + + information = (Thread_Information *) + _Objects_Information_table[ the_api ][ 1 ]; + _Assert( information != NULL ); + + return information; +} + /** * @brief Gets a thread by its identifier. * diff --git a/cpukit/rtems/src/taskconstruct.c b/cpukit/rtems/src/taskconstruct.c index 6ff83a0b9c..d33a850d88 100644 --- a/cpukit/rtems/src/taskconstruct.c +++ b/cpukit/rtems/src/taskconstruct.c @@ -79,6 +79,14 @@ rtems_status_code rtems_task_construct( return _RTEMS_tasks_Create( config, id, _RTEMS_tasks_Prepare_user_stack ); } +static void _RTEMS_tasks_Free( Thread_Control *the_thread ) +{ + Thread_Information *information; + + information = _Thread_Get_objects_information( the_thread ); + _Objects_Free( &information->Objects, &the_thread->Object ); +} + rtems_status_code _RTEMS_tasks_Create( const rtems_task_config *config, rtems_id *id, diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index b4204f7fbb..cf92e25a5d 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -130,16 +130,16 @@ static void _Thread_Add_to_zombie_chain( Thread_Control *the_thread ) static void _Thread_Make_zombie( Thread_Control *the_thread ) { + Thread_Information *information; + #if defined(RTEMS_SCORE_THREAD_ENABLE_RESOURCE_COUNT) if ( _Thread_Owns_resources( the_thread ) ) { _Internal_error( INTERNAL_ERROR_RESOURCE_IN_USE ); } #endif - _Objects_Close( - _Objects_Get_information_id( the_thread->Object.id ), - &the_thread->Object - ); + information = _Thread_Get_objects_information( the_thread ); + _Objects_Close( &information->Objects, &the_thread->Object ); _Thread_Set_state( the_thread, STATES_ZOMBIE ); _Thread_queue_Extract_with_proxy( the_thread ); @@ -157,8 +157,7 @@ static void _Thread_Make_zombie( Thread_Control *the_thread ) static void _Thread_Free( Thread_Control *the_thread ) { - Thread_Information *information = (Thread_Information *) - _Objects_Get_information_id( the_thread->Object.id ); + Thread_Information *information; _User_extensions_Thread_delete( the_thread ); _User_extensions_Destroy_iterators( the_thread ); @@ -179,6 +178,7 @@ static void _Thread_Free( Thread_Control *the_thread ) #endif #endif + information = _Thread_Get_objects_information( the_thread ); _Freechain_Push( &information->Thread_queue_heads.Free, the_thread->Wait.spare_heads -- 2.26.2 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel