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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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