source: rtems/c/src/exec/rtems/src/tasks.c @ aad726e

4.104.114.84.95
Last change on this file since aad726e was aad726e, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 22:56:38

Moved task_variable pointer to basic shared part of TCB instead of
RTEMS API extension to avoid problems when the extension is freed.
Eventually the task variable switch extension should become part
of the core context switch and the Ada tcb self implemented in
terms of it.

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/rtems/status.h>
18#include <rtems/rtems/support.h>
19#include <rtems/rtems/modes.h>
20#include <rtems/score/object.h>
21#include <rtems/score/stack.h>
22#include <rtems/score/states.h>
23#include <rtems/rtems/tasks.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/tod.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29#include <rtems/score/apiext.h>
30#include <rtems/score/sysstate.h>
31
32/*PAGE
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
43boolean _RTEMS_tasks_Create_extension(
44  Thread_Control *executing,
45  Thread_Control *created
46)
47{
48  RTEMS_API_Control *api;
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  return TRUE;
61}
62
63/*PAGE
64 *
65 *  _RTEMS_tasks_Start_extension
66 *
67 *  This extension routine is invoked when a task is started for the
68 *  first time.
69 */
70 
71User_extensions_routine _RTEMS_tasks_Start_extension(
72  Thread_Control *executing,
73  Thread_Control *started
74)
75{
76  RTEMS_API_Control *api;
77
78  api = started->API_Extensions[ THREAD_API_RTEMS ];
79 
80  api->pending_events = EVENT_SETS_NONE_PENDING;
81
82  _ASR_Initialize( &api->Signal );
83}
84
85/*PAGE
86 *
87 *  _RTEMS_tasks_Delete_extension
88 *
89 *  This extension routine is invoked when a task is deleted.
90 */
91 
92User_extensions_routine _RTEMS_tasks_Delete_extension(
93  Thread_Control *executing,
94  Thread_Control *deleted
95)
96{
97  rtems_task_variable_t *tvp, *next;
98
99  /*
100   *  Free per task variable memory
101   */
102
103  tvp = deleted->task_variables;
104  deleted->task_variables = NULL;
105  while (tvp) {
106    next = tvp->next;
107    _Workspace_Free( tvp );
108    tvp = next;
109  }
110
111  /*
112   *  Free API specific memory
113   */
114
115  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
116  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
117}
118
119/*PAGE
120 *
121 *  _RTEMS_tasks_Switch_extension
122 *
123 *  This extension routine is invoked at each context switch.
124 */
125 
126void _RTEMS_tasks_Switch_extension(
127  Thread_Control *executing,
128  Thread_Control *heir
129)
130{
131  rtems_task_variable_t *tvp;
132
133  /*
134   *  Per Task Variables
135   */
136
137  tvp = executing->task_variables;
138  while (tvp) {
139    tvp->var = *tvp->ptr;
140    tvp = tvp->next;
141  }
142
143  tvp = heir->task_variables;
144  while (tvp) {
145    *tvp->ptr = tvp->var;
146    tvp = tvp->next;
147  }
148}
149
150/*PAGE
151 *
152 *  _RTEMS_tasks_Post_switch_extension
153 *
154 *  This extension routine is invoked at each context switch.
155 */
156 
157void _RTEMS_tasks_Post_switch_extension(
158  Thread_Control *executing
159)
160{
161  ISR_Level          level;
162  RTEMS_API_Control *api;
163  ASR_Information   *asr;
164  rtems_signal_set   signal_set;
165  Modes_Control      prev_mode;
166
167  api = executing->API_Extensions[ THREAD_API_RTEMS ];
168
169  /*
170   *  Signal Processing
171   */
172
173  asr = &api->Signal;
174 
175  _ISR_Disable( level );
176    signal_set = asr->signals_posted;
177    asr->signals_posted = 0;
178  _ISR_Enable( level );
179 
180 
181  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
182    return;
183 
184  asr->nest_level += 1;
185  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
186 
187  (*asr->handler)( signal_set );
188
189  asr->nest_level -= 1;
190  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
191
192}
193
194API_extensions_Control _RTEMS_tasks_API_extensions = {
195  { NULL, NULL },
196  NULL,                                     /* predriver */
197  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
198  _RTEMS_tasks_Post_switch_extension        /* post switch */
199};
200
201User_extensions_Control _RTEMS_tasks_User_extensions = {
202  { NULL, NULL },
203  { _RTEMS_tasks_Create_extension,            /* create */
204    _RTEMS_tasks_Start_extension,             /* start */
205    _RTEMS_tasks_Start_extension,             /* restart */
206    _RTEMS_tasks_Delete_extension,            /* delete */
207    _RTEMS_tasks_Switch_extension,            /* switch */
208    NULL,                                     /* begin */
209    NULL,                                     /* exitted */
210    NULL                                      /* fatal */
211  }
212};
213
214/*PAGE
215 *
216 *  _RTEMS_tasks_Manager_initialization
217 *
218 *  This routine initializes all Task Manager related data structures.
219 *
220 *  Input parameters:
221 *    maximum_tasks       - number of tasks to initialize
222 *
223 *  Output parameters:  NONE
224 */
225
226void _RTEMS_tasks_Manager_initialization(
227  unsigned32                        maximum_tasks,
228  unsigned32                        number_of_initialization_tasks,
229  rtems_initialization_tasks_table *user_tasks
230)
231{
232
233  _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks;
234  _RTEMS_tasks_User_initialization_tasks = user_tasks;
235
236  /*
237   *  There may not be any RTEMS initialization tasks configured.
238   */
239
240#if 0
241  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
242    _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY );
243#endif
244
245  _Objects_Initialize_information(
246    &_RTEMS_tasks_Information,
247    OBJECTS_RTEMS_TASKS,
248    TRUE,
249    maximum_tasks,
250    sizeof( Thread_Control ),
251    FALSE,
252    RTEMS_MAXIMUM_NAME_LENGTH,
253    TRUE
254  );
255
256  /*
257   *  Add all the extensions for this API
258   */
259
260  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
261
262  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
263
264  /*
265   *  Register the MP Process Packet routine.
266   */
267
268#if defined(RTEMS_MULTIPROCESSING)
269  _MPCI_Register_packet_processor(
270    MP_PACKET_TASKS,
271    _RTEMS_tasks_MP_Process_packet
272  );
273#endif
274
275}
276
Note: See TracBrowser for help on using the repository browser.