source: rtems/cpukit/score/src/threadclose.c @ 632e4306

4.104.115
Last change on this file since 632e4306 was 345fc11, checked in by Joel Sherrill <joel.sherrill@…>, on 05/22/08 at 20:38:03

2008-05-22 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/task.h, itron/src/del_tsk.c, itron/src/exd_tsk.c, itron/src/task.c, posix/include/rtems/posix/threadsup.h, posix/src/cancel.c, posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c, posix/src/setcancelstate.c, posix/src/setcanceltype.c, posix/src/testcancel.c, rtems/src/taskdelete.c, score/inline/rtems/score/object.inl, score/src/objectclose.c, score/src/threadclose.c: Make all task delete/exit/cancel routines follow the same critical section pattern. Also ensure that POSIX cancelation routines are run at thread exit.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2008.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32
33/*
34 *  _Thread_Close
35 *
36 *  DESCRIPTION:
37 *
38 *  This routine frees all memory associated with the specified
39 *  thread and removes it from the local object table so no further
40 *  operations on this thread are allowed.
41 */
42
43void _Thread_Close(
44  Objects_Information  *information,
45  Thread_Control       *the_thread
46)
47{
48
49  /*
50   *  Now we are in a dispatching critical section again and we
51   *  can take the thread OUT of the published set.  It is invalid
52   *  to use this thread's Id after this call.  This will prevent
53   *  any other task from attempting to initiate a call on this task.
54   */
55  _Objects_Invalidate_Id( information, &the_thread->Object );
56
57  /*
58   *  We assume the Allocator Mutex is locked when we get here.
59   *  This provides sufficient protection to let the user extensions
60   *  run but as soon as we get back, we will make the thread
61   *  disappear and set a transient state on it.  So we temporarily
62   *  unnest dispatching.
63   */
64  _Thread_Unnest_dispatch();
65
66  _User_extensions_Thread_delete( the_thread );
67
68  _Thread_Disable_dispatch();
69
70  /*
71   *  Now we are in a dispatching critical section again and we
72   *  can take the thread OUT of the published set.  It is invalid
73   *  to use this thread's Id OR name after this call.
74   */
75  _Objects_Close( information, &the_thread->Object );
76
77  /*
78   *  By setting the dormant state, the thread will not be considered
79   *  for scheduling when we remove any blocking states.
80   */
81  _Thread_Set_state( the_thread, STATES_DORMANT );
82
83  if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) {
84    if ( _Watchdog_Is_active( &the_thread->Timer ) )
85      (void) _Watchdog_Remove( &the_thread->Timer );
86  }
87
88  /*
89   *  The thread might have been FP.  So deal with that.
90   */
91#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
92#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
93  if ( _Thread_Is_allocated_fp( the_thread ) )
94    _Thread_Deallocate_fp();
95#endif
96  the_thread->fp_context = NULL;
97
98  if ( the_thread->Start.fp_context )
99    (void) _Workspace_Free( the_thread->Start.fp_context );
100#endif
101
102  /*
103   *  Free the rest of the memory associated with this task
104   *  and set the associated pointers to NULL for safety.
105   */
106  _Thread_Stack_Free( the_thread );
107  the_thread->Start.stack = NULL;
108
109  if ( the_thread->extensions )
110    (void) _Workspace_Free( the_thread->extensions );
111  the_thread->extensions = NULL;
112}
Note: See TracBrowser for help on using the repository browser.