diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-02-28 16:15:35 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-02-28 16:15:35 +0000 |
commit | 5088d978385ce6d28db1731aab57b23ca1f6e9cc (patch) | |
tree | 2e061c7ff3c5287ac53f2945421425209cb2c33e /cpukit/score/src/threadclose.c | |
parent | 2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-5088d978385ce6d28db1731aab57b23ca1f6e9cc.tar.bz2 |
2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* itron/include/rtems/itron/task.h, itron/src/cre_tsk.c,
posix/src/pthreadcreate.c, rtems/src/taskcreate.c,
rtems/src/taskdelete.c, rtems/src/timerserver.c,
score/src/threadclose.c, score/src/threadcreateidle.c,
score/src/threadinitialize.c: Switch task create and delete
operations to using API Allocator Mutex. This moves almost all uses
of the RTEMS Workspace from dispatching disabled to mutex protected
which should improve deterministic behavior. The implementation was
carefully done to allow task create and delete extensions to invoke
more services. In particular, a task delete extension should be able
to do mutex and file operations.
Diffstat (limited to 'cpukit/score/src/threadclose.c')
-rw-r--r-- | cpukit/score/src/threadclose.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c index e506b2666d..f8231a1192 100644 --- a/cpukit/score/src/threadclose.c +++ b/cpukit/score/src/threadclose.c @@ -2,7 +2,7 @@ * Thread Handler * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -45,10 +45,30 @@ void _Thread_Close( Thread_Control *the_thread ) { + /* + * We assume the Allocator Mutex is locked when we get here. + * This provides sufficient protection to let the user extensions + * run but as soon as we get back, we will make the thread + * disappear and set a transient state on it. So we temporarily + * unnest dispatching. + */ + _Thread_Unnest_dispatch(); + _User_extensions_Thread_delete( the_thread ); + _Thread_Disable_dispatch(); + + /* + * Now we are in a dispatching critical section again and we + * can take the thread OUT of the published set. It is invalid + * to use this thread's Id after this call. + */ _Objects_Close( information, &the_thread->Object ); + /* + * By setting the transient state, the thread will not be considered + * for scheduling when we remove any blocking states. + */ _Thread_Set_state( the_thread, STATES_TRANSIENT ); if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) { @@ -56,6 +76,9 @@ void _Thread_Close( (void) _Watchdog_Remove( &the_thread->Timer ); } + /* + * The thread might have been FP. So deal with that. + */ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) if ( _Thread_Is_allocated_fp( the_thread ) ) @@ -67,11 +90,14 @@ void _Thread_Close( (void) _Workspace_Free( the_thread->Start.fp_context ); #endif + /* + * Free the rest of the memory associated with this task + * and set the associated pointers to NULL for safety. + */ _Thread_Stack_Free( the_thread ); + the_thread->Start.stack = NULL; if ( the_thread->extensions ) (void) _Workspace_Free( the_thread->extensions ); - - the_thread->Start.stack = NULL; the_thread->extensions = NULL; } |