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

Last change on this file since a3b4632 was a3b4632, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 4, 2005 at 9:53:58 PM

2005-10-04 Till Straumann <strauman@…>

PR 829/rtems

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