source: rtems/cpukit/rtems/src/tasks.c @ 5bda3a9

Last change on this file since 5bda3a9 was 5bda3a9, checked in by Joel Sherrill <joel.sherrill@…>, on 10/22/03 at 17:14:16

2003-10-22 Joel Sherrill <joel@…>

PR 512/core

  • src/tasks.c, src/taskvariabledelete.c: Run task variable destructor when task variable is deleted. Also some style cleanup.
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
18#include <rtems/rtems/modes.h>
19#include <rtems/score/object.h>
20#include <rtems/score/stack.h>
21#include <rtems/score/states.h>
22#include <rtems/rtems/tasks.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25#include <rtems/score/tod.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/score/apiext.h>
29#include <rtems/score/sysstate.h>
30
31/*PAGE
32 *
33 *  _RTEMS_tasks_Create_extension
34 *
35 *  This routine is an extension routine that is invoked as part
36 *  of creating any type of task or thread in the system.  If the
37 *  task is created via another API, then this routine is invoked
38 *  and this API given the opportunity to initialize its extension
39 *  area.
40 */
41
42boolean _RTEMS_tasks_Create_extension(
43  Thread_Control *executing,
44  Thread_Control *created
45)
46{
47  RTEMS_API_Control *api;
48  int                i;
49
50  api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) );
51
52  if ( !api )
53    return FALSE;
54
55  created->API_Extensions[ THREAD_API_RTEMS ] = api;
56 
57  api->pending_events = EVENT_SETS_NONE_PENDING;
58  _ASR_Initialize( &api->Signal );
59  created->task_variables = NULL;
60
61  for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
62    api->Notepads[i] = 0;
63
64  return TRUE;
65}
66
67/*PAGE
68 *
69 *  _RTEMS_tasks_Start_extension
70 *
71 *  This extension routine is invoked when a task is started for the
72 *  first time.
73 */
74 
75User_extensions_routine _RTEMS_tasks_Start_extension(
76  Thread_Control *executing,
77  Thread_Control *started
78)
79{
80  RTEMS_API_Control *api;
81
82  api = started->API_Extensions[ THREAD_API_RTEMS ];
83 
84  api->pending_events = EVENT_SETS_NONE_PENDING;
85
86  _ASR_Initialize( &api->Signal );
87}
88
89/*PAGE
90 *
91 *  _RTEMS_tasks_Delete_extension
92 *
93 *  This extension routine is invoked when a task is deleted.
94 */
95 
96User_extensions_routine _RTEMS_tasks_Delete_extension(
97  Thread_Control *executing,
98  Thread_Control *deleted
99)
100{
101  rtems_task_variable_t *tvp, *next;
102
103  /*
104   *  Free per task variable memory
105   */
106
107  tvp = deleted->task_variables;
108  deleted->task_variables = NULL;
109  while (tvp) {
110    next = tvp->next;
111    if  (tvp->dtor)
112        (*tvp->dtor)(*tvp->ptr);
113    if (_Thread_Is_executing(deleted))
114        *tvp->ptr = tvp->gval;
115    _Workspace_Free( tvp );
116    tvp = next;
117  }
118
119  /*
120   *  Free API specific memory
121   */
122
123  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
124  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
125}
126
127/*PAGE
128 *
129 *  _RTEMS_tasks_Switch_extension
130 *
131 *  This extension routine is invoked at each context switch.
132 */
133 
134void _RTEMS_tasks_Switch_extension(
135  Thread_Control *executing,
136  Thread_Control *heir
137)
138{
139  rtems_task_variable_t *tvp;
140
141  /*
142   *  Per Task Variables
143   */
144
145  tvp = executing->task_variables;
146  while (tvp) {
147    tvp->tval = *tvp->ptr;
148    *tvp->ptr = tvp->gval;
149    tvp = tvp->next;
150  }
151
152  tvp = heir->task_variables;
153  while (tvp) {
154    tvp->gval = *tvp->ptr;
155    *tvp->ptr = tvp->tval;
156    tvp = tvp->next;
157  }
158}
159
160/*PAGE
161 *
162 *  _RTEMS_tasks_Post_switch_extension
163 *
164 *  This extension routine is invoked at each context switch.
165 */
166 
167void _RTEMS_tasks_Post_switch_extension(
168  Thread_Control *executing
169)
170{
171  ISR_Level          level;
172  RTEMS_API_Control *api;
173  ASR_Information   *asr;
174  rtems_signal_set   signal_set;
175  Modes_Control      prev_mode;
176
177  api = executing->API_Extensions[ THREAD_API_RTEMS ];
178
179  /*
180   *  Signal Processing
181   */
182
183  asr = &api->Signal;
184 
185  _ISR_Disable( level );
186    signal_set = asr->signals_posted;
187    asr->signals_posted = 0;
188  _ISR_Enable( level );
189 
190 
191  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
192    return;
193 
194  asr->nest_level += 1;
195  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
196 
197  (*asr->handler)( signal_set );
198
199  asr->nest_level -= 1;
200  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
201
202}
203
204API_extensions_Control _RTEMS_tasks_API_extensions = {
205  { NULL, NULL },
206  NULL,                                     /* predriver */
207  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
208  _RTEMS_tasks_Post_switch_extension        /* post switch */
209};
210
211User_extensions_Control _RTEMS_tasks_User_extensions = {
212  { NULL, NULL },
213  { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
214  { _RTEMS_tasks_Create_extension,            /* create */
215    _RTEMS_tasks_Start_extension,             /* start */
216    _RTEMS_tasks_Start_extension,             /* restart */
217    _RTEMS_tasks_Delete_extension,            /* delete */
218    _RTEMS_tasks_Switch_extension,            /* switch */
219    NULL,                                     /* begin */
220    NULL,                                     /* exitted */
221    NULL                                      /* fatal */
222  }
223};
224
225/*PAGE
226 *
227 *  _RTEMS_tasks_Manager_initialization
228 *
229 *  This routine initializes all Task Manager related data structures.
230 *
231 *  Input parameters:
232 *    maximum_tasks       - number of tasks to initialize
233 *
234 *  Output parameters:  NONE
235 */
236
237void _RTEMS_tasks_Manager_initialization(
238  unsigned32                        maximum_tasks,
239  unsigned32                        number_of_initialization_tasks,
240  rtems_initialization_tasks_table *user_tasks
241)
242{
243
244  _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks;
245  _RTEMS_tasks_User_initialization_tasks = user_tasks;
246
247  /*
248   *  There may not be any RTEMS initialization tasks configured.
249   */
250
251#if 0
252  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
253    _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY );
254#endif
255
256  _Objects_Initialize_information(
257    &_RTEMS_tasks_Information, /* object information table */
258    OBJECTS_CLASSIC_API,       /* object API */
259    OBJECTS_RTEMS_TASKS,       /* object class */
260    maximum_tasks,             /* maximum objects of this class */
261    sizeof( Thread_Control ),  /* size of this object's control block */
262    FALSE,                     /* TRUE if the name is a string */
263    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
264#if defined(RTEMS_MULTIPROCESSING)
265    ,
266    TRUE,                      /* TRUE if this is a global object class */
267    NULL                       /* Proxy extraction support callout */
268#endif
269  );
270
271  /*
272   *  Add all the extensions for this API
273   */
274
275  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
276
277  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
278
279  /*
280   *  Register the MP Process Packet routine.
281   */
282
283#if defined(RTEMS_MULTIPROCESSING)
284  _MPCI_Register_packet_processor(
285    MP_PACKET_TASKS,
286    _RTEMS_tasks_MP_Process_packet
287  );
288#endif
289
290}
291
Note: See TracBrowser for help on using the repository browser.