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

4.115
Last change on this file since a112364 was a112364, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 15:30:26

score: Create threadq implementation header

Move implementation specific parts of tqdata.h, threadq.h and
threadq.inl into new header file threadqimpl.h. The threadq.h contains
now only the application visible API.

Delete tqdata.h.

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