summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/threadinitialize.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-30 00:14:26 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-30 00:14:26 +0000
commitcedfd802efaf0150cace14ce960f17aaf7d0c486 (patch)
treee1a0f2de135ff7ee01e4ee58b8889edc395780d5 /cpukit/score/src/threadinitialize.c
parent2009-07-29 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-cedfd802efaf0150cace14ce960f17aaf7d0c486.tar.bz2
2009-07-29 Joel Sherrill <joel.sherrill@oarcorp.com>
* score/src/threadinitialize.c: Rework so there is only one error exit path. This required setting every variable that contains memory allocated from the workspace to NULL early and using that assumption in the one failed exit path.
Diffstat (limited to 'cpukit/score/src/threadinitialize.c')
-rw-r--r--cpukit/score/src/threadinitialize.c117
1 files changed, 51 insertions, 66 deletions
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 2af727af7c..f4b9660526 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -57,29 +57,38 @@ bool _Thread_Initialize(
{
size_t actual_stack_size = 0;
void *stack = NULL;
-#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
- void *fp_area;
-#endif
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ void *fp_area;
+ #endif
void *extensions_area;
bool extension_status;
+ int i;
-#if __RTEMS_ADA__
/*
* Initialize the Ada self pointer
*/
-
- the_thread->rtems_ada_self = NULL;
-#endif
+ #if __RTEMS_ADA__
+ the_thread->rtems_ada_self = NULL;
+ #endif
/*
- * Allocate and Initialize the stack for this thread.
+ * Zero out all the allocated memory fields
*/
+ for ( i=0 ; i <= THREAD_API_LAST ; i++ )
+ the_thread->API_Extensions[i] = NULL;
+ extensions_area = NULL;
+ the_thread->libc_reent = NULL;
- if ( !stack_area ) {
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ fp_area = NULL;
+ #endif
+ /*
+ * Allocate and Initialize the stack for this thread.
+ */
+ 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 */
@@ -100,62 +109,37 @@ bool _Thread_Initialize(
/*
* Allocate the floating point area for this thread
*/
-
-#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
- if ( is_fp ) {
-
- fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
- if ( !fp_area ) {
- _Thread_Stack_Free( the_thread );
- return false;
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ if ( is_fp ) {
+ fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
+ if ( !fp_area )
+ goto failed;
+ fp_area = _Context_Fp_start( fp_area, 0 );
}
- fp_area = _Context_Fp_start( fp_area, 0 );
-
- } else
- fp_area = NULL;
-
- the_thread->fp_context = fp_area;
- the_thread->Start.fp_context = fp_area;
-#endif
+ the_thread->fp_context = fp_area;
+ the_thread->Start.fp_context = fp_area;
+ #endif
/*
* Initialize the thread timer
*/
_Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- /*Initialize the head of chain of mutex */
- _Chain_Initialize_empty(&the_thread->lock_mutex);
-#endif
-
- /*
- * Clear the libc reent hook.
- */
-
- the_thread->libc_reent = NULL;
+ #ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ /* Initialize the head of chain of held mutexes */
+ _Chain_Initialize_empty(&the_thread->lock_mutex);
+ #endif
/*
* Allocate the extensions area for this thread
*/
-
if ( _Thread_Maximum_extensions ) {
extensions_area = _Workspace_Allocate(
(_Thread_Maximum_extensions + 1) * sizeof( void * )
);
-
- if ( !extensions_area ) {
-#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
- if ( fp_area )
- (void) _Workspace_Free( fp_area );
-#endif
-
- _Thread_Stack_Free( the_thread );
-
- return false;
- }
- } else
- extensions_area = NULL;
-
+ if ( !extensions_area )
+ goto failed;
+ }
the_thread->extensions = (void **) extensions_area;
/*
@@ -165,10 +149,8 @@ bool _Thread_Initialize(
* so they cannot rely on the thread create user extension
* call.
*/
-
if ( the_thread->extensions ) {
- uint32_t i;
- for ( i = 0; i < (_Thread_Maximum_extensions + 1); i++ )
+ for ( i = 0; i <= _Thread_Maximum_extensions ; i++ )
the_thread->extensions[i] = NULL;
}
@@ -206,7 +188,6 @@ bool _Thread_Initialize(
/*
* Initialize the CPU usage statistics
*/
-
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
_Timestamp_Set_to_zero( &the_thread->cpu_time_used );
#else
@@ -216,7 +197,6 @@ bool _Thread_Initialize(
/*
* Open the object
*/
-
_Objects_Open( information, &the_thread->Object, name );
/*
@@ -227,22 +207,27 @@ bool _Thread_Initialize(
* run safely.
*/
extension_status = _User_extensions_Thread_create( the_thread );
+ if ( extension_status )
+ return true;
- if ( !extension_status ) {
+failed:
+ if ( the_thread->libc_reent )
+ _Workspace_Free( the_thread->libc_reent );
- if ( extensions_area )
- (void) _Workspace_Free( extensions_area );
+ for ( i=0 ; i <= THREAD_API_LAST ; i++ )
+ if ( the_thread->API_Extensions[i] )
+ _Workspace_Free( the_thread->API_Extensions[i] );
+
+ if ( extensions_area )
+ (void) _Workspace_Free( extensions_area );
-#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
if ( fp_area )
(void) _Workspace_Free( fp_area );
-#endif
-
- _Thread_Stack_Free( the_thread );
+ #endif
- return false;
- }
+ _Thread_Stack_Free( the_thread );
+ return false;
- return true;
}