source: rtems/cpukit/rtems/src/tasks.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 6.0 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    _Workspace_Free( tvp );
107    tvp = next;
108  }
109
110  /*
111   *  Free API specific memory
112   */
113
114  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
115  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
116}
117
118/*PAGE
119 *
120 *  _RTEMS_tasks_Switch_extension
121 *
122 *  This extension routine is invoked at each context switch.
123 */
124 
125void _RTEMS_tasks_Switch_extension(
126  Thread_Control *executing,
127  Thread_Control *heir
128)
129{
130  rtems_task_variable_t *tvp;
131
132  /*
133   *  Per Task Variables
134   */
135
136  tvp = executing->task_variables;
137  while (tvp) {
138    tvp->var = *tvp->ptr;
139    tvp = tvp->next;
140  }
141
142  tvp = heir->task_variables;
143  while (tvp) {
144    *tvp->ptr = tvp->var;
145    tvp = tvp->next;
146  }
147}
148
149/*PAGE
150 *
151 *  _RTEMS_tasks_Post_switch_extension
152 *
153 *  This extension routine is invoked at each context switch.
154 */
155 
156void _RTEMS_tasks_Post_switch_extension(
157  Thread_Control *executing
158)
159{
160  ISR_Level          level;
161  RTEMS_API_Control *api;
162  ASR_Information   *asr;
163  rtems_signal_set   signal_set;
164  Modes_Control      prev_mode;
165
166  api = executing->API_Extensions[ THREAD_API_RTEMS ];
167
168  /*
169   *  Signal Processing
170   */
171
172  asr = &api->Signal;
173 
174  _ISR_Disable( level );
175    signal_set = asr->signals_posted;
176    asr->signals_posted = 0;
177  _ISR_Enable( level );
178 
179 
180  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
181    return;
182 
183  asr->nest_level += 1;
184  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
185 
186  (*asr->handler)( signal_set );
187
188  asr->nest_level -= 1;
189  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
190
191}
192
193API_extensions_Control _RTEMS_tasks_API_extensions = {
194  { NULL, NULL },
195  NULL,                                     /* predriver */
196  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
197  _RTEMS_tasks_Post_switch_extension        /* post switch */
198};
199
200User_extensions_Control _RTEMS_tasks_User_extensions = {
201  { NULL, NULL },
202  { _RTEMS_tasks_Create_extension,            /* create */
203    _RTEMS_tasks_Start_extension,             /* start */
204    _RTEMS_tasks_Start_extension,             /* restart */
205    _RTEMS_tasks_Delete_extension,            /* delete */
206    _RTEMS_tasks_Switch_extension,            /* switch */
207    NULL,                                     /* begin */
208    NULL,                                     /* exitted */
209    NULL                                      /* fatal */
210  }
211};
212
213/*PAGE
214 *
215 *  _RTEMS_tasks_Manager_initialization
216 *
217 *  This routine initializes all Task Manager related data structures.
218 *
219 *  Input parameters:
220 *    maximum_tasks       - number of tasks to initialize
221 *
222 *  Output parameters:  NONE
223 */
224
225void _RTEMS_tasks_Manager_initialization(
226  unsigned32                        maximum_tasks,
227  unsigned32                        number_of_initialization_tasks,
228  rtems_initialization_tasks_table *user_tasks
229)
230{
231
232  _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks;
233  _RTEMS_tasks_User_initialization_tasks = user_tasks;
234
235  /*
236   *  There may not be any RTEMS initialization tasks configured.
237   */
238
239#if 0
240  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
241    _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY );
242#endif
243
244  _Objects_Initialize_information(
245    &_RTEMS_tasks_Information,
246    OBJECTS_RTEMS_TASKS,
247    TRUE,
248    maximum_tasks,
249    sizeof( Thread_Control ),
250    FALSE,
251    RTEMS_MAXIMUM_NAME_LENGTH,
252    TRUE
253  );
254
255  /*
256   *  Add all the extensions for this API
257   */
258
259  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
260
261  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
262
263  /*
264   *  Register the MP Process Packet routine.
265   */
266
267#if defined(RTEMS_MULTIPROCESSING)
268  _MPCI_Register_packet_processor(
269    MP_PACKET_TASKS,
270    _RTEMS_tasks_MP_Process_packet
271  );
272#endif
273
274}
275
Note: See TracBrowser for help on using the repository browser.