From 0bde56b1b4ef7468188712c86e6bd2793532ddc9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sat, 7 Dec 2019 16:28:21 +0100 Subject: score: Simplify thread stack free Update #3835. --- cpukit/include/rtems/score/stackimpl.h | 9 +++++++++ cpukit/include/rtems/score/thread.h | 9 +++++---- cpukit/include/rtems/score/threadimpl.h | 11 ----------- cpukit/score/src/threadinitialize.c | 27 +++++++++------------------ cpukit/score/src/threadrestart.c | 3 ++- cpukit/score/src/threadstackfree.c | 32 +++++++------------------------- 6 files changed, 32 insertions(+), 59 deletions(-) diff --git a/cpukit/include/rtems/score/stackimpl.h b/cpukit/include/rtems/score/stackimpl.h index 6b14560c9b..f4671dea60 100644 --- a/cpukit/include/rtems/score/stackimpl.h +++ b/cpukit/include/rtems/score/stackimpl.h @@ -115,6 +115,15 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Ensure_minimum ( */ void *_Stack_Allocate( size_t stack_size ); +/** + * @brief Free the stack area allocated by _Stack_Allocate(). + * + * Do nothing if the stack area is NULL. + * + * @param stack_area The stack area to free, or NULL. + */ +void _Stack_Free( void *stack_area ); + /** @} */ #ifdef __cplusplus diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h index 5c62efc1f7..336be281bd 100644 --- a/cpukit/include/rtems/score/thread.h +++ b/cpukit/include/rtems/score/thread.h @@ -199,10 +199,11 @@ typedef struct { uint32_t isr_level; /** This field is the initial priority. */ Priority_Control initial_priority; - #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) - /** This field indicates whether the SuperCore allocated the stack. */ - bool core_allocated_stack; - #endif + /** + * @brief This field is a pointer to the allocated stack area, otherwise it + * is NULL. + */ + void *allocated_stack; /** This field is the stack information. */ Stack_Control Initial_stack; #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index 3ff6c94777..1289a3002f 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -124,17 +124,6 @@ void _Thread_Create_idle(void); */ void _Thread_Start_multitasking( void ) RTEMS_NO_RETURN; -/** - * @brief Deallocates thread stack. - * - * Deallocate the Thread's stack. - * - * @param[out] the_thread The thread to deallocate the stack of. - */ -void _Thread_Stack_Free( - Thread_Control *the_thread -); - /** * @brief Initializes thread. * diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index 3b04ed26ab..c6e8abf979 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -86,30 +86,21 @@ bool _Thread_Initialize( (char *) the_thread + add_on->source_offset; } - /* - * Allocate and Initialize the stack for this thread. - */ - #if !defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) + /* Allocate the stack for this thread */ +#if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) + if ( stack_area == NULL ) { +#endif stack_size = _Stack_Ensure_minimum( stack_size ); stack_area = _Stack_Allocate( stack_size ); if ( stack_area == NULL ) { return false; } - #else - if ( stack_area == NULL ) { - stack_size = _Stack_Ensure_minimum( stack_size ); - stack_area = _Stack_Allocate( stack_size ); - - if ( stack_area == NULL ) { - return false; - } - the_thread->Start.core_allocated_stack = true; - } else { - the_thread->Start.core_allocated_stack = false; - } - #endif + the_thread->Start.allocated_stack = stack_area; +#if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) + } +#endif _Stack_Initialize( &the_thread->Start.Initial_stack, @@ -320,6 +311,6 @@ failed: _Workspace_Free( fp_area ); #endif - _Thread_Stack_Free( the_thread ); + _Stack_Free( the_thread->Start.allocated_stack ); return false; } diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index 83aef28c30..6ff9b44515 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -184,7 +185,7 @@ static void _Thread_Free( Thread_Control *the_thread ) * Free the rest of the memory associated with this task * and set the associated pointers to NULL for safety. */ - _Thread_Stack_Free( the_thread ); + _Stack_Free( the_thread->Start.allocated_stack ); _Workspace_Free( the_thread->Start.tls_area ); diff --git a/cpukit/score/src/threadstackfree.c b/cpukit/score/src/threadstackfree.c index 312a10c7f3..8d8e2296a7 100644 --- a/cpukit/score/src/threadstackfree.c +++ b/cpukit/score/src/threadstackfree.c @@ -1,8 +1,9 @@ /** - * @file + * @file * - * @brief Deallocate Thread Stack - * @ingroup RTEMSScoreThread + * @ingroup RTEMSScoreStack + * + * @brief Deallocate Thread Stack */ /* @@ -18,29 +19,10 @@ #include "config.h" #endif -#include +#include #include -void _Thread_Stack_Free( - Thread_Control *the_thread -) +void _Stack_Free( void *stack_area ) { - rtems_stack_free_hook stack_free_hook = - rtems_configuration_get_stack_free_hook(); - - #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) - /* - * If the API provided the stack space, then don't free it. - */ - if ( !the_thread->Start.core_allocated_stack ) - return; - #endif - - /* - * Call ONLY the CPU table stack free hook, or the - * the RTEMS workspace free. This is so the free - * routine properly matches the allocation of the stack. - */ - - (*stack_free_hook)( the_thread->Start.Initial_stack.area ); + ( *rtems_configuration_get_stack_free_hook() )( stack_area ); } -- cgit v1.2.3