diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-25 10:54:49 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-31 08:29:43 +0200 |
commit | 1b1be254e7a3e3d6fe6d55d62010a81a7ef35411 (patch) | |
tree | c8bacf15b0f092728fd69debcb2387b65db33ed0 /cpukit/posix/src/pthread.c | |
parent | score: Replace _Thread_Reset() (diff) | |
download | rtems-1b1be254e7a3e3d6fe6d55d62010a81a7ef35411.tar.bz2 |
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.
Diffstat (limited to 'cpukit/posix/src/pthread.c')
-rw-r--r-- | cpukit/posix/src/pthread.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c index 0416e28adf..8d1a8eb209 100644 --- a/cpukit/posix/src/pthread.c +++ b/cpukit/posix/src/pthread.c @@ -274,21 +274,30 @@ static void _POSIX_Threads_Delete_extension( Thread_Control *deleted ) { + _Workspace_Free( deleted->API_Extensions[ THREAD_API_POSIX ] ); +} + +static void _POSIX_Threads_Terminate_extension( + Thread_Control *executing +) +{ Thread_Control *the_thread; POSIX_API_Control *api; void **value_ptr; - api = deleted->API_Extensions[ THREAD_API_POSIX ]; + api = executing->API_Extensions[ THREAD_API_POSIX ]; /* * Run the POSIX cancellation handlers */ - _POSIX_Threads_cancel_run( deleted ); + _POSIX_Threads_cancel_run( executing ); + + _Thread_Disable_dispatch(); /* * Wakeup all the tasks which joined with this one */ - value_ptr = (void **) deleted->Wait.return_argument; + value_ptr = (void **) executing->Wait.return_argument; while ( (the_thread = _Thread_queue_Dequeue( &api->Join_List )) ) *(void **)the_thread->Wait.return_argument = value_ptr; @@ -296,9 +305,7 @@ static void _POSIX_Threads_Delete_extension( if ( api->schedpolicy == SCHED_SPORADIC ) (void) _Watchdog_Remove( &api->Sporadic_timer ); - deleted->API_Extensions[ THREAD_API_POSIX ] = NULL; - - _Workspace_Free( api ); + _Thread_Enable_dispatch(); } /* @@ -350,7 +357,8 @@ User_extensions_Control _POSIX_Threads_User_extensions = { NULL, /* switch */ NULL, /* begin */ _POSIX_Threads_Exitted_extension, /* exitted */ - NULL /* fatal */ + NULL, /* fatal */ + _POSIX_Threads_Terminate_extension /* terminate */ } }; |