[PATCH] score: Add _Thread_Demand_objects_information()

Gedare Bloom gedare at rtems.org
Wed Jan 27 19:17:31 UTC 2021


On Wed, Jan 27, 2021 at 11:38 AM Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> We do not need all the checks if we have a valid indentifier to a thread
> class object.
>
> 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 | 25 +++++++++++++++++++++++++
>  cpukit/rtems/src/taskconstruct.c        |  8 ++++++++
>  cpukit/score/src/threadrestart.c        | 12 ++++++------
>  4 files changed, 39 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 52945b407c..eb2810db73 100644
> --- a/cpukit/include/rtems/score/threadimpl.h
> +++ b/cpukit/include/rtems/score/threadimpl.h
> @@ -842,6 +842,31 @@ RTEMS_INLINE_ROUTINE Objects_Information
> *_Thread_Get_objects_information(
>    return _Objects_Information_table[ the_api ][ 1 ];
>  }
>
> +/**
> + * @brief Demands the thread object information associated with the object
> + *   identifier.
> + *
> + * @param id is a valid identifier to a thread class object.
> + *
> + * @return Returns the thread object information associated with the
> identifier.
> + */
> +RTEMS_INLINE_ROUTINE Thread_Information
> *_Thread_Demand_objects_information(
> +  Objects_Id id
> +)
> +{
> +  size_t              the_api;
> +  Thread_Information *information;
> +
> +  the_api = (size_t) _Objects_Get_API( id );
> +  _Assert( _Objects_Is_api_valid( the_api ) );
> +
> +  information = (Thread_Information *)
> +    _Objects_Information_table[ the_api ][ 1 ];
> +  _Assert( information != NULL );
> +
> +  return information;
> +}
> +
>
what does this add beyond _Thread_Get_objects_information? not clear to me


>  /**
>   * @brief Gets a thread by its identifier.
>   *
> diff --git a/cpukit/rtems/src/taskconstruct.c
> b/cpukit/rtems/src/taskconstruct.c
> index 6ff83a0b9c..656db7a674 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_Demand_objects_information( the_thread->Object.id
> );
> +  _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..5670abdc26 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_Demand_objects_information( the_thread->Object.id
> );
> +  _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_Demand_objects_information( the_thread->Object.id
> );
>    _Freechain_Push(
>      &information->Thread_queue_heads.Free,
>      the_thread->Wait.spare_heads
> --
> 2.26.2
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20210127/ac57a631/attachment-0001.html>


More information about the devel mailing list