summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-12-07 16:28:21 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-02-12 09:08:36 +0100
commit0bde56b1b4ef7468188712c86e6bd2793532ddc9 (patch)
treeaaca04985241fb16cb1ad6c856e5c87f6fd8a36e
parenta0211fc9f9883d0a1182548de11ab0e0505a81c6 (diff)
score: Simplify thread stack free
Update #3835.
-rw-r--r--cpukit/include/rtems/score/stackimpl.h9
-rw-r--r--cpukit/include/rtems/score/thread.h9
-rw-r--r--cpukit/include/rtems/score/threadimpl.h11
-rw-r--r--cpukit/score/src/threadinitialize.c27
-rw-r--r--cpukit/score/src/threadrestart.c3
-rw-r--r--cpukit/score/src/threadstackfree.c32
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
@@ -125,17 +125,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.
*
* This routine initializes the specified the thread. It allocates
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 <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 );
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 <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 );
}