source: rtems/cpukit/score/src/threadclose.c @ a0323a9f

4.115
Last change on this file since a0323a9f was a0323a9f, checked in by Joel Sherrill <joel.sherrill@…>, on 02/16/11 at 00:24:49

2011-02-15 Joel Sherrill <joel.sherrilL@…>

  • libmisc/capture/capture.c, posix/src/keyfreememory.c, posix/src/pthread.c, score/include/rtems/score/wkspace.h, score/src/objectextendinformation.c, score/src/objectnamespaceremove.c, score/src/objectsetname.c, score/src/threadclose.c, score/src/threadinitialize.c, score/src/wkspace.c: Many places were checking for a NULL pointer before calling _Workspace_Free. By moving the check into _Workspace_Free, we eliminate a number of conditional paths and make it harder to return a NULL pointer.
  • 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 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/scheduler.h>
27#include <rtems/score/states.h>
28#include <rtems/score/sysstate.h>
29#include <rtems/score/thread.h>
30#include <rtems/score/threadq.h>
31#include <rtems/score/userext.h>
32#include <rtems/score/wkspace.h>
33
34/*
35 *  _Thread_Close
36 *
37 *  DESCRIPTION:
38 *
39 *  This routine frees all memory associated with the specified
40 *  thread and removes it from the local object table so no further
41 *  operations on this thread are allowed.
42 */
43
44void _Thread_Close(
45  Objects_Information  *information,
46  Thread_Control       *the_thread
47)
48{
49
50  /*
51   *  Now we are in a dispatching critical section again and we
52   *  can take the thread OUT of the published set.  It is invalid
53   *  to use this thread's Id after this call.  This will prevent
54   *  any other task from attempting to initiate a call on this task.
55   */
56  _Objects_Invalidate_Id( information, &the_thread->Object );
57
58  /*
59   *  We assume the Allocator Mutex is locked when we get here.
60   *  This provides sufficient protection to let the user extensions
61   *  run but as soon as we get back, we will make the thread
62   *  disappear and set a transient state on it.  So we temporarily
63   *  unnest dispatching.
64   */
65  _Thread_Unnest_dispatch();
66
67  _User_extensions_Thread_delete( the_thread );
68
69  _Thread_Disable_dispatch();
70
71  /*
72   *  Now we are in a dispatching critical section again and we
73   *  can take the thread OUT of the published set.  It is invalid
74   *  to use this thread's Id OR name after this call.
75   */
76  _Objects_Close( information, &the_thread->Object );
77
78  /*
79   *  By setting the dormant state, the thread will not be considered
80   *  for scheduling when we remove any blocking states.
81   */
82  _Thread_Set_state( the_thread, STATES_DORMANT );
83
84  if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) {
85    if ( _Watchdog_Is_active( &the_thread->Timer ) )
86      (void) _Watchdog_Remove( &the_thread->Timer );
87  }
88
89  /*
90   * Free the per-thread scheduling information.
91   */
92  _Scheduler_Thread_scheduler_free( &_Scheduler, the_thread );
93
94  /*
95   *  The thread might have been FP.  So deal with that.
96   */
97#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
98#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
99  if ( _Thread_Is_allocated_fp( the_thread ) )
100    _Thread_Deallocate_fp();
101#endif
102  the_thread->fp_context = NULL;
103
104  _Workspace_Free( the_thread->Start.fp_context );
105#endif
106
107  /*
108   *  Free the rest of the memory associated with this task
109   *  and set the associated pointers to NULL for safety.
110   */
111  _Thread_Stack_Free( the_thread );
112  the_thread->Start.stack = NULL;
113
114  _Workspace_Free( the_thread->extensions );
115  the_thread->extensions = NULL;
116}
Note: See TracBrowser for help on using the repository browser.