From a0211fc9f9883d0a1182548de11ab0e0505a81c6 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sat, 7 Dec 2019 16:00:58 +0100 Subject: score: Simplify thread stack allocation Remove superfluous Thread_Control::Start::stack member. Update #3835. --- cpukit/score/src/threadinitialize.c | 29 ++++++++++++++--------------- cpukit/score/src/threadstackallocate.c | 28 +++++----------------------- 2 files changed, 19 insertions(+), 38 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index 83c689eee4..3b04ed26ab 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -43,8 +43,6 @@ bool _Thread_Initialize( ) { uintptr_t tls_size = _TLS_Get_size(); - size_t actual_stack_size = 0; - void *stack = NULL; #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) void *fp_area = NULL; #endif @@ -92,30 +90,31 @@ bool _Thread_Initialize( * Allocate and Initialize the stack for this thread. */ #if !defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API) - actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size ); - if ( !actual_stack_size || actual_stack_size < stack_size ) - return false; /* stack allocation failed */ + stack_size = _Stack_Ensure_minimum( stack_size ); + stack_area = _Stack_Allocate( stack_size ); - stack = the_thread->Start.stack; + if ( stack_area == NULL ) { + return false; + } #else - if ( !stack_area ) { - actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size ); - if ( !actual_stack_size || actual_stack_size < stack_size ) - return false; /* stack allocation failed */ + if ( stack_area == NULL ) { + stack_size = _Stack_Ensure_minimum( stack_size ); + stack_area = _Stack_Allocate( stack_size ); + + if ( stack_area == NULL ) { + return false; + } - stack = the_thread->Start.stack; the_thread->Start.core_allocated_stack = true; } else { - stack = stack_area; - actual_stack_size = stack_size; the_thread->Start.core_allocated_stack = false; } #endif _Stack_Initialize( &the_thread->Start.Initial_stack, - stack, - actual_stack_size + stack_area, + stack_size ); scheduler_index = 0; diff --git a/cpukit/score/src/threadstackallocate.c b/cpukit/score/src/threadstackallocate.c index fd89d7f07f..722de7bfd6 100644 --- a/cpukit/score/src/threadstackallocate.c +++ b/cpukit/score/src/threadstackallocate.c @@ -1,11 +1,11 @@ /** * @file - * + * + * @ingroup RTEMSScoreStack + * * @brief Stack Allocate Helper - * @ingroup RTEMSScoreThread */ - /* * COPYRIGHT (c) 1989-2010. * On-Line Applications Research Corporation (OAR). @@ -19,28 +19,10 @@ #include "config.h" #endif -#include #include #include -size_t _Thread_Stack_Allocate( - Thread_Control *the_thread, - size_t stack_size -) +void *_Stack_Allocate( size_t stack_size ) { - void *stack_addr = 0; - size_t the_stack_size; - rtems_stack_allocate_hook stack_allocate_hook = - rtems_configuration_get_stack_allocate_hook(); - - the_stack_size = _Stack_Ensure_minimum( stack_size ); - - stack_addr = (*stack_allocate_hook)( the_stack_size ); - - if ( !stack_addr ) - the_stack_size = 0; - - the_thread->Start.stack = stack_addr; - - return the_stack_size; + return ( *rtems_configuration_get_stack_allocate_hook() )( stack_size ); } -- cgit v1.2.3