source: rtems/cpukit/rtems/src/tasks.c @ 484a769

4.104.114.95
Last change on this file since 484a769 was 484a769, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/04/08 at 17:46:39

Convert to "bool".

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