source: rtems/cpukit/rtems/src/tasks.c @ 3f727f98

4.104.115
Last change on this file since 3f727f98 was 3f727f98, checked in by Joel Sherrill <joel.sherrill@…>, on 09/26/09 at 16:17:00

2009-09-26 Joel Sherrill <joel.sherrill@…>

  • libmisc/capture/capture.c, posix/src/pthread.c, rtems/src/tasks.c, score/include/rtems/score/userext.h: Eliminate use of deprecated rtems_extension. Re-add prototype for _User_extensions_Add_API_set.
  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 *  RTEMS Task Manager -- Initialize Manager
3 *
4 *  COPYRIGHT (c) 1989-2009.
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  api->event_condition = 0;
72  _ASR_Initialize( &api->Signal );
73  created->task_variables = NULL;
74
75  if ( rtems_configuration_get_notepads_enabled() ) {
76    for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
77      api->Notepads[i] = 0;
78  }
79
80  return true;
81}
82
83/*PAGE
84 *
85 *  _RTEMS_tasks_Start_extension
86 *
87 *  This extension routine is invoked when a task is started for the
88 *  first time.
89 */
90
91void _RTEMS_tasks_Start_extension(
92  Thread_Control *executing,
93  Thread_Control *started
94)
95{
96  RTEMS_API_Control *api;
97
98  api = started->API_Extensions[ THREAD_API_RTEMS ];
99
100  api->pending_events = EVENT_SETS_NONE_PENDING;
101}
102
103/*PAGE
104 *
105 *  _RTEMS_tasks_Delete_extension
106 *
107 *  This extension routine is invoked when a task is deleted.
108 */
109
110void _RTEMS_tasks_Delete_extension(
111  Thread_Control *executing,
112  Thread_Control *deleted
113)
114{
115  rtems_task_variable_t *tvp, *next;
116
117  /*
118   *  Free per task variable memory
119   */
120
121  tvp = deleted->task_variables;
122  deleted->task_variables = NULL;
123  while (tvp) {
124    next = (rtems_task_variable_t *)tvp->next;
125    _RTEMS_Tasks_Invoke_task_variable_dtor( deleted, tvp );
126    tvp = next;
127  }
128
129  /*
130   *  Free API specific memory
131   */
132
133  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
134  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
135}
136
137/*PAGE
138 *
139 *  _RTEMS_tasks_Switch_extension
140 *
141 *  This extension routine is invoked at each context switch.
142 */
143
144void _RTEMS_tasks_Switch_extension(
145  Thread_Control *executing,
146  Thread_Control *heir
147)
148{
149  rtems_task_variable_t *tvp;
150
151  /*
152   *  Per Task Variables
153   */
154
155  tvp = executing->task_variables;
156  while (tvp) {
157    tvp->tval = *tvp->ptr;
158    *tvp->ptr = tvp->gval;
159    tvp = (rtems_task_variable_t *)tvp->next;
160  }
161
162  tvp = heir->task_variables;
163  while (tvp) {
164    tvp->gval = *tvp->ptr;
165    *tvp->ptr = tvp->tval;
166    tvp = (rtems_task_variable_t *)tvp->next;
167  }
168}
169
170/*PAGE
171 *
172 *  _RTEMS_tasks_Post_switch_extension
173 *
174 *  This extension routine is invoked at each context switch.
175 */
176
177void _RTEMS_tasks_Post_switch_extension(
178  Thread_Control *executing
179)
180{
181  ISR_Level          level;
182  RTEMS_API_Control *api;
183  ASR_Information   *asr;
184  rtems_signal_set   signal_set;
185  Modes_Control      prev_mode;
186
187  api = executing->API_Extensions[ THREAD_API_RTEMS ];
188  if ( !api )
189    return;
190
191  /*
192   *  Signal Processing
193   */
194
195  asr = &api->Signal;
196
197  _ISR_Disable( level );
198    signal_set = asr->signals_posted;
199    asr->signals_posted = 0;
200  _ISR_Enable( level );
201
202
203  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
204    return;
205
206  asr->nest_level += 1;
207  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
208
209  (*asr->handler)( signal_set );
210
211  asr->nest_level -= 1;
212  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
213
214}
215
216API_extensions_Control _RTEMS_tasks_API_extensions = {
217  { NULL, NULL },
218  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
219    NULL,                                   /* predriver */
220  #endif
221  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
222  _RTEMS_tasks_Post_switch_extension        /* post switch */
223};
224
225User_extensions_Control _RTEMS_tasks_User_extensions = {
226  { NULL, NULL },
227  { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
228  { _RTEMS_tasks_Create_extension,            /* create */
229    _RTEMS_tasks_Start_extension,             /* start */
230    _RTEMS_tasks_Start_extension,             /* restart */
231    _RTEMS_tasks_Delete_extension,            /* delete */
232    _RTEMS_tasks_Switch_extension,            /* switch */
233    NULL,                                     /* begin */
234    NULL,                                     /* exitted */
235    NULL                                      /* fatal */
236  }
237};
238
239/*PAGE
240 *
241 *  _RTEMS_tasks_Manager_initialization
242 *
243 *  This routine initializes all Task Manager related data structures.
244 *
245 *  Input parameters: NONE
246 *
247 *  Output parameters:  NONE
248 */
249
250void _RTEMS_tasks_Manager_initialization(void)
251{
252  _Objects_Initialize_information(
253    &_RTEMS_tasks_Information, /* object information table */
254    OBJECTS_CLASSIC_API,       /* object API */
255    OBJECTS_RTEMS_TASKS,       /* object class */
256    Configuration_RTEMS_API.maximum_tasks,
257                               /* maximum objects of this class */
258    sizeof( Thread_Control ),  /* size of this object's control block */
259    false,                     /* true if the name is a string */
260    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
261#if defined(RTEMS_MULTIPROCESSING)
262    ,
263    true,                      /* true if this is a global object class */
264    NULL                       /* Proxy extraction support callout */
265#endif
266  );
267
268  /*
269   *  Add all the extensions for this API
270   */
271
272  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
273
274  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
275
276  /*
277   *  Register the MP Process Packet routine.
278   */
279
280#if defined(RTEMS_MULTIPROCESSING)
281  _MPCI_Register_packet_processor(
282    MP_PACKET_TASKS,
283    _RTEMS_tasks_MP_Process_packet
284  );
285#endif
286
287}
288
289/*PAGE
290 *
291 *  _RTEMS_tasks_Initialize_user_tasks
292 *
293 *  This routine creates and starts all configured user
294 *  initialzation threads.
295 *
296 *  Input parameters: NONE
297 *
298 *  Output parameters:  NONE
299 */
300
301void _RTEMS_tasks_Initialize_user_tasks( void )
302{
303  if ( _RTEMS_tasks_Initialize_user_tasks_p )
304    (*_RTEMS_tasks_Initialize_user_tasks_p)();
305}
Note: See TracBrowser for help on using the repository browser.