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

4.115
Last change on this file since a2e3f33 was a2e3f33, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 11:50:54

score: Create object implementation header

Move implementation specific parts of object.h and object.inl into new
header file objectimpl.h. The object.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Task API Extensions
5 *  @ingroup ClassicTasks
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/config.h>
23#include <rtems/rtems/asrimpl.h>
24#include <rtems/rtems/eventimpl.h>
25#include <rtems/rtems/status.h>
26#include <rtems/rtems/support.h>
27#include <rtems/rtems/modes.h>
28#include <rtems/score/stack.h>
29#include <rtems/rtems/tasksimpl.h>
30#include <rtems/score/thread.h>
31#include <rtems/score/tod.h>
32#include <rtems/score/userextimpl.h>
33#include <rtems/score/wkspace.h>
34#include <rtems/score/apiext.h>
35
36/*
37 *  _RTEMS_tasks_Create_extension
38 *
39 *  This routine is an extension routine that is invoked as part
40 *  of creating any type of task or thread in the system.  If the
41 *  task is created via another API, then this routine is invoked
42 *  and this API given the opportunity to initialize its extension
43 *  area.
44 */
45
46static bool _RTEMS_tasks_Create_extension(
47  Thread_Control *executing,
48  Thread_Control *created
49)
50{
51  RTEMS_API_Control *api;
52  int                i;
53  size_t             to_allocate;
54
55  /*
56   *  Notepads must be the last entry in the structure and they
57   *  can be left off if disabled in the configuration.
58   */
59  to_allocate = sizeof( RTEMS_API_Control );
60  if ( !rtems_configuration_get_notepads_enabled() )
61    to_allocate -= (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t));
62
63  api = _Workspace_Allocate( to_allocate );
64
65  if ( !api )
66    return false;
67
68  created->API_Extensions[ THREAD_API_RTEMS ] = api;
69
70  _Event_Initialize( &api->Event );
71  _Event_Initialize( &api->System_event );
72  _ASR_Initialize( &api->Signal );
73  created->task_variables = NULL;
74
75  if ( rtems_configuration_get_notepads_enabled() ) {
76    for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
77      api->Notepads[i] = 0;
78  }
79
80  return true;
81}
82
83/*
84 *  _RTEMS_tasks_Start_extension
85 *
86 *  This extension routine is invoked when a task is started for the
87 *  first time.
88 */
89
90static void _RTEMS_tasks_Start_extension(
91  Thread_Control *executing,
92  Thread_Control *started
93)
94{
95  RTEMS_API_Control *api;
96
97  api = started->API_Extensions[ THREAD_API_RTEMS ];
98
99  _Event_Initialize( &api->Event );
100  _Event_Initialize( &api->System_event );
101}
102
103/*
104 *  _RTEMS_tasks_Delete_extension
105 *
106 *  This extension routine is invoked when a task is deleted.
107 */
108
109static void _RTEMS_tasks_Delete_extension(
110  Thread_Control *executing,
111  Thread_Control *deleted
112)
113{
114  rtems_task_variable_t *tvp, *next;
115
116  /*
117   *  Free per task variable memory
118   */
119
120  tvp = deleted->task_variables;
121  deleted->task_variables = NULL;
122  while (tvp) {
123    next = (rtems_task_variable_t *)tvp->next;
124    _RTEMS_Tasks_Invoke_task_variable_dtor( deleted, tvp );
125    tvp = next;
126  }
127
128  /*
129   *  Free API specific memory
130   */
131
132  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
133  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
134}
135
136/*
137 *  _RTEMS_tasks_Switch_extension
138 *
139 *  This extension routine is invoked at each context switch.
140 */
141
142static void _RTEMS_tasks_Switch_extension(
143  Thread_Control *executing,
144  Thread_Control *heir
145)
146{
147  rtems_task_variable_t *tvp;
148
149  /*
150   *  Per Task Variables
151   */
152
153  tvp = executing->task_variables;
154  while (tvp) {
155    tvp->tval = *tvp->ptr;
156    *tvp->ptr = tvp->gval;
157    tvp = (rtems_task_variable_t *)tvp->next;
158  }
159
160  tvp = heir->task_variables;
161  while (tvp) {
162    tvp->gval = *tvp->ptr;
163    *tvp->ptr = tvp->tval;
164    tvp = (rtems_task_variable_t *)tvp->next;
165  }
166}
167
168API_extensions_Control _RTEMS_tasks_API_extensions = {
169  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
170    .predriver_hook = NULL,
171  #endif
172  .postdriver_hook = _RTEMS_tasks_Initialize_user_tasks
173};
174
175User_extensions_Control _RTEMS_tasks_User_extensions = {
176  { NULL, NULL },
177  { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
178  { _RTEMS_tasks_Create_extension,            /* create */
179    _RTEMS_tasks_Start_extension,             /* start */
180    _RTEMS_tasks_Start_extension,             /* restart */
181    _RTEMS_tasks_Delete_extension,            /* delete */
182    _RTEMS_tasks_Switch_extension,            /* switch */
183    NULL,                                     /* begin */
184    NULL,                                     /* exitted */
185    NULL                                      /* fatal */
186  }
187};
188
189void _RTEMS_tasks_Manager_initialization(void)
190{
191  _Objects_Initialize_information(
192    &_RTEMS_tasks_Information, /* object information table */
193    OBJECTS_CLASSIC_API,       /* object API */
194    OBJECTS_RTEMS_TASKS,       /* object class */
195    Configuration_RTEMS_API.maximum_tasks,
196                               /* maximum objects of this class */
197    sizeof( Thread_Control ),  /* size of this object's control block */
198    false,                     /* true if the name is a string */
199    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
200#if defined(RTEMS_MULTIPROCESSING)
201    ,
202    true,                      /* true if this is a global object class */
203    NULL                       /* Proxy extraction support callout */
204#endif
205  );
206
207  /*
208   *  Add all the extensions for this API
209   */
210
211  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
212
213  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
214
215  /*
216   *  Register the MP Process Packet routine.
217   */
218
219#if defined(RTEMS_MULTIPROCESSING)
220  _MPCI_Register_packet_processor(
221    MP_PACKET_TASKS,
222    _RTEMS_tasks_MP_Process_packet
223  );
224#endif
225
226}
227
228void _RTEMS_tasks_Initialize_user_tasks( void )
229{
230  if ( _RTEMS_tasks_Initialize_user_tasks_p )
231    (*_RTEMS_tasks_Initialize_user_tasks_p)();
232}
Note: See TracBrowser for help on using the repository browser.