diff options
Diffstat (limited to 'cpukit/score/src')
-rw-r--r-- | cpukit/score/src/threadclose.c | 2 | ||||
-rw-r--r-- | cpukit/score/src/threadinitialize.c | 18 | ||||
-rw-r--r-- | cpukit/score/src/threadloadenv.c | 3 | ||||
-rw-r--r-- | cpukit/score/src/wkspace.c | 30 |
4 files changed, 52 insertions, 1 deletions
diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c index df70f508ad..82c4ab4a39 100644 --- a/cpukit/score/src/threadclose.c +++ b/cpukit/score/src/threadclose.c @@ -96,4 +96,6 @@ void _Thread_Close( _Workspace_Free( the_thread->extensions ); the_thread->extensions = NULL; + + _Workspace_Free( the_thread->Start.tls_area ); } diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index 34198caa80..bc2600afcb 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -20,6 +20,7 @@ #include <rtems/score/threadimpl.h> #include <rtems/score/schedulerimpl.h> #include <rtems/score/stackimpl.h> +#include <rtems/score/tls.h> #include <rtems/score/userextimpl.h> #include <rtems/score/watchdogimpl.h> #include <rtems/score/wkspace.h> @@ -48,6 +49,7 @@ bool _Thread_Initialize( void *extensions_area; bool extension_status; int i; + uintptr_t tls_size = (uintptr_t) _TLS_Size; #if defined( RTEMS_SMP ) if ( rtems_configuration_is_smp_enabled() && !is_preemptible ) { @@ -70,6 +72,7 @@ bool _Thread_Initialize( extensions_area = NULL; the_thread->libc_reent = NULL; + the_thread->Start.tls_area = NULL; #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) fp_area = NULL; @@ -105,6 +108,19 @@ bool _Thread_Initialize( actual_stack_size ); + /* Thread-local storage (TLS) area allocation */ + if ( tls_size > 0 ) { + uintptr_t tls_align = _TLS_Heap_align_up( (uintptr_t) _TLS_Alignment ); + uintptr_t tls_alloc = _TLS_Get_allocation_size( tls_size, tls_align ); + + the_thread->Start.tls_area = + _Workspace_Allocate_aligned( tls_alloc, tls_align ); + + if ( the_thread->Start.tls_area == NULL ) { + goto failed; + } + } + /* * Allocate the floating point area for this thread */ @@ -223,6 +239,8 @@ bool _Thread_Initialize( return true; failed: + _Workspace_Free( the_thread->Start.tls_area ); + _Workspace_Free( the_thread->libc_reent ); for ( i=0 ; i <= THREAD_API_LAST ; i++ ) diff --git a/cpukit/score/src/threadloadenv.c b/cpukit/score/src/threadloadenv.c index eb3cc63ca7..49821b0697 100644 --- a/cpukit/score/src/threadloadenv.c +++ b/cpukit/score/src/threadloadenv.c @@ -58,7 +58,8 @@ void _Thread_Load_environment( the_thread->Start.Initial_stack.size, isr_level, _Thread_Handler, - is_fp + is_fp, + the_thread->Start.tls_area ); } diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c index 65806863c2..f437b885c0 100644 --- a/cpukit/score/src/wkspace.c +++ b/cpukit/score/src/wkspace.c @@ -21,6 +21,8 @@ #include <rtems/score/wkspace.h> #include <rtems/score/heapimpl.h> #include <rtems/score/interr.h> +#include <rtems/score/threadimpl.h> +#include <rtems/score/tls.h> #include <rtems/config.h> #include <string.h> /* for memset */ @@ -30,6 +32,25 @@ #include <rtems/bspIo.h> #endif +static uint32_t _Get_maximum_thread_count(void) +{ + uint32_t thread_count = 0; + + thread_count += _Thread_Get_maximum_internal_threads(); + + thread_count += rtems_resource_maximum_per_allocation( + Configuration_RTEMS_API.maximum_tasks + ); + +#if defined(RTEMS_POSIX_API) + thread_count += rtems_resource_maximum_per_allocation( + Configuration_POSIX_API.maximum_threads + ); +#endif + + return thread_count; +} + void _Workspace_Handler_initialization( Heap_Area *areas, size_t area_count, @@ -42,8 +63,17 @@ void _Workspace_Handler_initialization( bool unified = rtems_configuration_get_unified_work_area(); uintptr_t page_size = CPU_HEAP_ALIGNMENT; uintptr_t overhead = _Heap_Area_overhead( page_size ); + uintptr_t tls_size = (uintptr_t) _TLS_Size; size_t i; + if ( tls_size > 0 ) { + uintptr_t tls_alignment = (uintptr_t) _TLS_Alignment; + uintptr_t tls_alloc = _TLS_Get_allocation_size( tls_size, tls_alignment ); + + remaining += _Get_maximum_thread_count() + * _Heap_Size_with_overhead( page_size, tls_alloc, tls_alignment ); + } + for (i = 0; i < area_count; ++i) { Heap_Area *area = &areas [i]; |