From 1b1be254e7a3e3d6fe6d55d62010a81a7ef35411 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 25 Mar 2014 10:54:49 +0100 Subject: score: Thread life cycle re-implementation The thread deletion is now supported on SMP. This change fixes the following PRs: PR1814: SMP race condition between stack free and dispatch PR2035: psxcancel reveals NULL pointer access in _Thread_queue_Extract() The POSIX cleanup handler are now called in the right context (should be called in the context of the terminating thread). http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html Add a user extension the reflects a thread termination event. This is used to reclaim the Newlib reentrancy structure (may use file operations), the POSIX cleanup handlers and the POSIX key destructors. --- cpukit/rtems/src/tasks.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'cpukit/rtems/src/tasks.c') diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c index c859d248b5..594695080a 100644 --- a/cpukit/rtems/src/tasks.c +++ b/cpukit/rtems/src/tasks.c @@ -112,6 +112,17 @@ static void _RTEMS_tasks_Delete_extension( Thread_Control *executing, Thread_Control *deleted ) +{ + /* + * Free API specific memory + */ + + (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); +} + +static void _RTEMS_tasks_Terminate_extension( + Thread_Control *executing +) { rtems_task_variable_t *tvp, *next; @@ -119,25 +130,18 @@ static void _RTEMS_tasks_Delete_extension( * Free per task variable memory */ - tvp = deleted->task_variables; - deleted->task_variables = NULL; + tvp = executing->task_variables; + executing->task_variables = NULL; while (tvp) { next = (rtems_task_variable_t *)tvp->next; - _RTEMS_Tasks_Invoke_task_variable_dtor( deleted, tvp ); + _RTEMS_Tasks_Invoke_task_variable_dtor( executing, tvp ); tvp = next; } /* * Run all the key destructors */ - _POSIX_Keys_Run_destructors( deleted ); - - /* - * Free API specific memory - */ - - (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); - deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL; + _POSIX_Keys_Run_destructors( executing ); } /* @@ -189,7 +193,8 @@ User_extensions_Control _RTEMS_tasks_User_extensions = { _RTEMS_tasks_Switch_extension, /* switch */ NULL, /* begin */ NULL, /* exitted */ - NULL /* fatal */ + NULL, /* fatal */ + _RTEMS_tasks_Terminate_extension /* terminate */ } }; -- cgit v1.2.3