source: rtems/cpukit/rtems/src/tasks.c @ ebe61382

4.104.114.95
Last change on this file since ebe61382 was 6f1384c, checked in by Joel Sherrill <joel.sherrill@…>, on 05/21/07 at 23:19:36

Split Classic API data instantiation into individual files. This reduces the size of the BSS section when an optional manageer stub is used. Some tests showed about a 600 byte reduction in BSS size. Also eliminated the variables _RTEMS_tasks_User_initialization_tasks and _RTEMS_tasks_Number_of_initialization_tasks because they were only used in one place after initialized. It was a waste of space.

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