score: Simplify thread stack free

Update #3835.
This commit is contained in:
Sebastian Huber
2019-12-07 16:28:21 +01:00
parent a0211fc9f9
commit 0bde56b1b4
6 changed files with 32 additions and 59 deletions

View File

@@ -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

View File

@@ -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 )

View File

@@ -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.
*

View File

@@ -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;
}

View File

@@ -26,6 +26,7 @@
#include <rtems/score/chainimpl.h>
#include <rtems/score/isrlock.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/stackimpl.h>
#include <rtems/score/sysstate.h>
#include <rtems/score/threadqimpl.h>
#include <rtems/score/userextimpl.h>
@@ -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 );

View File

@@ -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 <rtems/score/threadimpl.h>
#include <rtems/score/stackimpl.h>
#include <rtems/config.h>
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 );
}