source: rtems/cpukit/rtems/src/tasks.c @ 90015e7f

4.104.114.84.95
Last change on this file since 90015e7f was 90015e7f, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:32:31

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/rtems.h, inline/rtems/rtems/region.inl, macros/rtems/rtems/region.inl, src/dpmem.c, src/dpmemcreate.c, src/msg.c, src/msgqcreate.c, src/part.c, src/partcreate.c, src/ratemon.c, src/ratemoncreate.c, src/region.c, src/regioncreate.c, src/regiondelete.c, src/regionextend.c, src/regiongetinfo.c, src/regiongetsegment.c, src/regiongetsegmentsize.c, src/regionident.c, src/regionreturnsegment.c, src/rtemstimer.c, src/sem.c, src/semcreate.c, src/taskcreate.c, src/taskident.c, src/tasks.c, src/timercreate.c: Modified as part of above.
  • Property mode set to 100644
File size: 6.7 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.OARcorp.com/rtems/license.html.
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
49  api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) );
50
51  if ( !api )
52    return FALSE;
53
54  created->API_Extensions[ THREAD_API_RTEMS ] = api;
55 
56  api->pending_events = EVENT_SETS_NONE_PENDING;
57  _ASR_Initialize( &api->Signal );
58  created->task_variables = NULL;
59  return TRUE;
60}
61
62/*PAGE
63 *
64 *  _RTEMS_tasks_Start_extension
65 *
66 *  This extension routine is invoked when a task is started for the
67 *  first time.
68 */
69 
70User_extensions_routine _RTEMS_tasks_Start_extension(
71  Thread_Control *executing,
72  Thread_Control *started
73)
74{
75  RTEMS_API_Control *api;
76
77  api = started->API_Extensions[ THREAD_API_RTEMS ];
78 
79  api->pending_events = EVENT_SETS_NONE_PENDING;
80
81  _ASR_Initialize( &api->Signal );
82}
83
84/*PAGE
85 *
86 *  _RTEMS_tasks_Delete_extension
87 *
88 *  This extension routine is invoked when a task is deleted.
89 */
90 
91User_extensions_routine _RTEMS_tasks_Delete_extension(
92  Thread_Control *executing,
93  Thread_Control *deleted
94)
95{
96  rtems_task_variable_t *tvp, *next;
97
98  /*
99   *  Free per task variable memory
100   */
101
102  tvp = deleted->task_variables;
103  deleted->task_variables = NULL;
104  while (tvp) {
105    next = tvp->next;
106    if  (tvp->dtor)
107        (*tvp->dtor)(*tvp->ptr );
108    if (executing == deleted)
109        *tvp->ptr = tvp->gval;
110    _Workspace_Free( tvp );
111    tvp = next;
112  }
113
114  /*
115   *  Free API specific memory
116   */
117
118  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
119  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
120}
121
122/*PAGE
123 *
124 *  _RTEMS_tasks_Switch_extension
125 *
126 *  This extension routine is invoked at each context switch.
127 */
128 
129void _RTEMS_tasks_Switch_extension(
130  Thread_Control *executing,
131  Thread_Control *heir
132)
133{
134  rtems_task_variable_t *tvp;
135
136  /*
137   *  Per Task Variables
138   */
139
140  tvp = executing->task_variables;
141  while (tvp) {
142    tvp->tval = *tvp->ptr;
143    *tvp->ptr = tvp->gval;
144    tvp = tvp->next;
145  }
146
147  tvp = heir->task_variables;
148  while (tvp) {
149    tvp->gval = *tvp->ptr;
150    *tvp->ptr = tvp->tval;
151    tvp = tvp->next;
152  }
153}
154
155/*PAGE
156 *
157 *  _RTEMS_tasks_Post_switch_extension
158 *
159 *  This extension routine is invoked at each context switch.
160 */
161 
162void _RTEMS_tasks_Post_switch_extension(
163  Thread_Control *executing
164)
165{
166  ISR_Level          level;
167  RTEMS_API_Control *api;
168  ASR_Information   *asr;
169  rtems_signal_set   signal_set;
170  Modes_Control      prev_mode;
171
172  api = executing->API_Extensions[ THREAD_API_RTEMS ];
173
174  /*
175   *  Signal Processing
176   */
177
178  asr = &api->Signal;
179 
180  _ISR_Disable( level );
181    signal_set = asr->signals_posted;
182    asr->signals_posted = 0;
183  _ISR_Enable( level );
184 
185 
186  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
187    return;
188 
189  asr->nest_level += 1;
190  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
191 
192  (*asr->handler)( signal_set );
193
194  asr->nest_level -= 1;
195  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
196
197}
198
199API_extensions_Control _RTEMS_tasks_API_extensions = {
200  { NULL, NULL },
201  NULL,                                     /* predriver */
202  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
203  _RTEMS_tasks_Post_switch_extension        /* post switch */
204};
205
206User_extensions_Control _RTEMS_tasks_User_extensions = {
207  { NULL, NULL },
208  { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
209  { _RTEMS_tasks_Create_extension,            /* create */
210    _RTEMS_tasks_Start_extension,             /* start */
211    _RTEMS_tasks_Start_extension,             /* restart */
212    _RTEMS_tasks_Delete_extension,            /* delete */
213    _RTEMS_tasks_Switch_extension,            /* switch */
214    NULL,                                     /* begin */
215    NULL,                                     /* exitted */
216    NULL                                      /* fatal */
217  }
218};
219
220/*PAGE
221 *
222 *  _RTEMS_tasks_Manager_initialization
223 *
224 *  This routine initializes all Task Manager related data structures.
225 *
226 *  Input parameters:
227 *    maximum_tasks       - number of tasks to initialize
228 *
229 *  Output parameters:  NONE
230 */
231
232void _RTEMS_tasks_Manager_initialization(
233  unsigned32                        maximum_tasks,
234  unsigned32                        number_of_initialization_tasks,
235  rtems_initialization_tasks_table *user_tasks
236)
237{
238
239  _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks;
240  _RTEMS_tasks_User_initialization_tasks = user_tasks;
241
242  /*
243   *  There may not be any RTEMS initialization tasks configured.
244   */
245
246#if 0
247  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
248    _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY );
249#endif
250
251  _Objects_Initialize_information(
252    &_RTEMS_tasks_Information, /* object information table */
253    OBJECTS_CLASSIC_API,       /* object API */
254    OBJECTS_RTEMS_TASKS,       /* object class */
255    maximum_tasks,             /* maximum objects of this class */
256    sizeof( Thread_Control ),  /* size of this object's control block */
257    FALSE,                     /* TRUE if the name is a string */
258    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
259#if defined(RTEMS_MULTIPROCESSING)
260    ,
261    FALSE,                     /* TRUE if this is a global object class */
262    NULL                       /* Proxy extraction support callout */
263#endif
264  );
265
266  /*
267   *  Add all the extensions for this API
268   */
269
270  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
271
272  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
273
274  /*
275   *  Register the MP Process Packet routine.
276   */
277
278#if defined(RTEMS_MULTIPROCESSING)
279  _MPCI_Register_packet_processor(
280    MP_PACKET_TASKS,
281    _RTEMS_tasks_MP_Process_packet
282  );
283#endif
284
285}
286
Note: See TracBrowser for help on using the repository browser.