source: rtems/cpukit/score/src/threadclose.c @ 4fc370e

4.115
Last change on this file since 4fc370e was 4fc370e, checked in by Sebastian Huber <sebastian.huber@…>, on 06/05/13 at 10:08:23

score: Move thread dispatch content to new file

Move thread dispatch declarations and inline functions to new header
<rtems/score/threaddispatch.h> to make it independent of the
Thread_Control structure. This avoids a cyclic dependency in case
thread dispatch functions are used for the object implementation.

  • Property mode set to 100644
File size: 3.0 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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
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>
28#include <rtems/score/scheduler.h>
29#include <rtems/score/states.h>
30#include <rtems/score/sysstate.h>
31#include <rtems/score/thread.h>
32#include <rtems/score/threaddispatch.h>
33#include <rtems/score/threadq.h>
34#include <rtems/score/userextimpl.h>
35#include <rtems/score/wkspace.h>
36
37void _Thread_Close(
38  Objects_Information  *information,
39  Thread_Control       *the_thread
40)
41{
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
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
59  _User_extensions_Thread_delete( the_thread );
60
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
66   *  to use this thread's Id OR name after this call.
67   */
68  _Objects_Close( information, &the_thread->Object );
69
70  /*
71   *  By setting the dormant state, the thread will not be considered
72   *  for scheduling when we remove any blocking states.
73   */
74  _Thread_Set_state( the_thread, STATES_DORMANT );
75
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
81  /*
82   * Free the per-thread scheduling information.
83   */
84  _Scheduler_Free( the_thread );
85
86  /*
87   *  The thread might have been FP.  So deal with that.
88   */
89#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
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
96  _Workspace_Free( the_thread->Start.fp_context );
97#endif
98
99  /*
100   *  Free the rest of the memory associated with this task
101   *  and set the associated pointers to NULL for safety.
102   */
103  _Thread_Stack_Free( the_thread );
104  the_thread->Start.stack = NULL;
105
106  _Workspace_Free( the_thread->extensions );
107  the_thread->extensions = NULL;
108}
Note: See TracBrowser for help on using the repository browser.