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

4.115
Last change on this file since 3be0c9a was 3be0c9a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/12 at 13:51:25

score: Add and use <rtems/score/userextimpl.h>

This file contains the parts of <rtems/score/userext.h> that are only
necessary for the RTEMS implementation.

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