[f2f63d1] | 1 | /** |
---|
| 2 | * @file |
---|
[05df0a8] | 3 | * |
---|
[f2f63d1] | 4 | * @brief Thread Close |
---|
| 5 | * @ingroup ScoreThread |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[010192d] | 9 | * COPYRIGHT (c) 1989-2011. |
---|
[05df0a8] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 13 | * found in the file LICENSE in this distribution or at |
---|
[dd687d97] | 14 | * http://www.rtems.com/license/LICENSE. |
---|
[05df0a8] | 15 | */ |
---|
| 16 | |
---|
[a8eed23] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[05df0a8] | 21 | #include <rtems/system.h> |
---|
| 22 | #include <rtems/score/apiext.h> |
---|
| 23 | #include <rtems/score/context.h> |
---|
| 24 | #include <rtems/score/interr.h> |
---|
| 25 | #include <rtems/score/isr.h> |
---|
| 26 | #include <rtems/score/object.h> |
---|
| 27 | #include <rtems/score/priority.h> |
---|
[0faa9dad] | 28 | #include <rtems/score/scheduler.h> |
---|
[05df0a8] | 29 | #include <rtems/score/states.h> |
---|
| 30 | #include <rtems/score/sysstate.h> |
---|
| 31 | #include <rtems/score/thread.h> |
---|
[4fc370e] | 32 | #include <rtems/score/threaddispatch.h> |
---|
[05df0a8] | 33 | #include <rtems/score/threadq.h> |
---|
[3be0c9a] | 34 | #include <rtems/score/userextimpl.h> |
---|
[05df0a8] | 35 | #include <rtems/score/wkspace.h> |
---|
| 36 | |
---|
| 37 | void _Thread_Close( |
---|
| 38 | Objects_Information *information, |
---|
| 39 | Thread_Control *the_thread |
---|
| 40 | ) |
---|
| 41 | { |
---|
[345fc11] | 42 | /* |
---|
| 43 | * Now we are in a dispatching critical section again and we |
---|
| 44 | * can take the thread OUT of the published set. It is invalid |
---|
| 45 | * to use this thread's Id after this call. This will prevent |
---|
| 46 | * any other task from attempting to initiate a call on this task. |
---|
| 47 | */ |
---|
| 48 | _Objects_Invalidate_Id( information, &the_thread->Object ); |
---|
| 49 | |
---|
[5088d97] | 50 | /* |
---|
| 51 | * We assume the Allocator Mutex is locked when we get here. |
---|
| 52 | * This provides sufficient protection to let the user extensions |
---|
| 53 | * run but as soon as we get back, we will make the thread |
---|
| 54 | * disappear and set a transient state on it. So we temporarily |
---|
| 55 | * unnest dispatching. |
---|
| 56 | */ |
---|
| 57 | _Thread_Unnest_dispatch(); |
---|
| 58 | |
---|
[588a5901] | 59 | _User_extensions_Thread_delete( the_thread ); |
---|
[05279b84] | 60 | |
---|
[5088d97] | 61 | _Thread_Disable_dispatch(); |
---|
| 62 | |
---|
| 63 | /* |
---|
| 64 | * Now we are in a dispatching critical section again and we |
---|
| 65 | * can take the thread OUT of the published set. It is invalid |
---|
[345fc11] | 66 | * to use this thread's Id OR name after this call. |
---|
[5088d97] | 67 | */ |
---|
[05df0a8] | 68 | _Objects_Close( information, &the_thread->Object ); |
---|
[05279b84] | 69 | |
---|
[5088d97] | 70 | /* |
---|
[d9aca5f5] | 71 | * By setting the dormant state, the thread will not be considered |
---|
[5088d97] | 72 | * for scheduling when we remove any blocking states. |
---|
| 73 | */ |
---|
[d9aca5f5] | 74 | _Thread_Set_state( the_thread, STATES_DORMANT ); |
---|
[05279b84] | 75 | |
---|
[05df0a8] | 76 | if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) { |
---|
| 77 | if ( _Watchdog_Is_active( &the_thread->Timer ) ) |
---|
| 78 | (void) _Watchdog_Remove( &the_thread->Timer ); |
---|
| 79 | } |
---|
| 80 | |
---|
[0faa9dad] | 81 | /* |
---|
| 82 | * Free the per-thread scheduling information. |
---|
| 83 | */ |
---|
[108c4b0] | 84 | _Scheduler_Free( the_thread ); |
---|
[0faa9dad] | 85 | |
---|
[5088d97] | 86 | /* |
---|
| 87 | * The thread might have been FP. So deal with that. |
---|
| 88 | */ |
---|
[ca7858bb] | 89 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
[05df0a8] | 90 | #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) |
---|
| 91 | if ( _Thread_Is_allocated_fp( the_thread ) ) |
---|
| 92 | _Thread_Deallocate_fp(); |
---|
| 93 | #endif |
---|
| 94 | the_thread->fp_context = NULL; |
---|
| 95 | |
---|
[a0323a9f] | 96 | _Workspace_Free( the_thread->Start.fp_context ); |
---|
[ca7858bb] | 97 | #endif |
---|
[05df0a8] | 98 | |
---|
[5088d97] | 99 | /* |
---|
| 100 | * Free the rest of the memory associated with this task |
---|
| 101 | * and set the associated pointers to NULL for safety. |
---|
| 102 | */ |
---|
[05df0a8] | 103 | _Thread_Stack_Free( the_thread ); |
---|
[5088d97] | 104 | the_thread->Start.stack = NULL; |
---|
[05df0a8] | 105 | |
---|
[a0323a9f] | 106 | _Workspace_Free( the_thread->extensions ); |
---|
[05df0a8] | 107 | the_thread->extensions = NULL; |
---|
| 108 | } |
---|