mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-22 04:25:16 +08:00
score: Add _Thread_Get_objects_information()
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.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user