source: rtems/cpukit/rtems/src/tasks.c @ 54c3fbd

5
Last change on this file since 54c3fbd was 54c3fbd, checked in by Sebastian Huber <sebastian.huber@…>, on 12/11/15 at 10:09:13

score: Initialize thread control to zero

This reduces the code size of the thread initialization.

  • 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-2014.
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.org/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/signalimpl.h>
26#include <rtems/rtems/status.h>
27#include <rtems/rtems/support.h>
28#include <rtems/rtems/modes.h>
29#include <rtems/rtems/tasksimpl.h>
30#include <rtems/posix/keyimpl.h>
31#include <rtems/score/stack.h>
32#include <rtems/score/threadimpl.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  size_t             i;
54
55  api = created->API_Extensions[ THREAD_API_RTEMS ];
56
57  _ASR_Create( &api->Signal );
58
59  return true;
60}
61
62/*
63 *  _RTEMS_tasks_Start_extension
64 *
65 *  This extension routine is invoked when a task is started for the
66 *  first time.
67 */
68
69static void _RTEMS_tasks_Start_extension(
70  Thread_Control *executing,
71  Thread_Control *started
72)
73{
74  RTEMS_API_Control *api;
75
76  api = started->API_Extensions[ THREAD_API_RTEMS ];
77
78  _Event_Initialize( &api->Event );
79  _Event_Initialize( &api->System_event );
80}
81
82static void _RTEMS_tasks_Delete_extension(
83  Thread_Control *executing,
84  Thread_Control *deleted
85)
86{
87  RTEMS_API_Control *api;
88
89  api = deleted->API_Extensions[ THREAD_API_RTEMS ];
90
91  _ASR_Destroy( &api->Signal );
92}
93
94static void _RTEMS_tasks_Terminate_extension(
95  Thread_Control *executing
96)
97{
98  /*
99   *  Free per task variable memory
100   *
101   *  Per Task Variables are only enabled in uniprocessor configurations.
102   */
103  #if !defined(RTEMS_SMP)
104    /*
105     * We know this is deprecated and don't want a warning on every BSP built.
106     */
107    #pragma GCC diagnostic push
108    #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
109    do {
110      rtems_task_variable_t *tvp, *next;
111
112      tvp = executing->task_variables;
113      executing->task_variables = NULL;
114      while (tvp) {
115        next = (rtems_task_variable_t *)tvp->next;
116        _RTEMS_Tasks_Invoke_task_variable_dtor( executing, tvp );
117        tvp = next;
118      }
119    } while (0);
120    #pragma GCC diagnostic pop
121  #endif
122
123  /*
124   *  Run all the key destructors
125   */
126  _POSIX_Keys_Run_destructors( executing );
127}
128
129#if !defined(RTEMS_SMP)
130/*
131 *  _RTEMS_tasks_Switch_extension
132 *
133 *  This extension routine is invoked at each context switch.
134 *
135 *  @note Since this only needs to address per-task variables, it is
136 *        disabled entirely for SMP configurations.
137 */
138static void _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 are only enabled in uniprocessor configurations
147   */
148
149  tvp = executing->task_variables;
150  while (tvp) {
151    tvp->tval = *tvp->ptr;
152    *tvp->ptr = tvp->gval;
153    tvp = (rtems_task_variable_t *)tvp->next;
154  }
155
156  tvp = heir->task_variables;
157  while (tvp) {
158    tvp->gval = *tvp->ptr;
159    *tvp->ptr = tvp->tval;
160    tvp = (rtems_task_variable_t *)tvp->next;
161  }
162}
163#define RTEMS_TASKS_SWITCH_EXTENSION _RTEMS_tasks_Switch_extension
164#else
165#define RTEMS_TASKS_SWITCH_EXTENSION NULL
166#endif
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    _RTEMS_tasks_Terminate_extension          /* terminate */
187  }
188};
189
190void _RTEMS_tasks_Manager_initialization(void)
191{
192  _Thread_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    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#endif
204  );
205
206  /*
207   *  Add all the extensions for this API
208   */
209
210  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
211
212  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
213
214  /*
215   *  Register the MP Process Packet routine.
216   */
217
218#if defined(RTEMS_MULTIPROCESSING)
219  _MPCI_Register_packet_processor(
220    MP_PACKET_TASKS,
221    _RTEMS_tasks_MP_Process_packet
222  );
223#endif
224
225}
226
227void _RTEMS_tasks_Initialize_user_tasks( void )
228{
229  if ( _RTEMS_tasks_Initialize_user_tasks_p )
230    (*_RTEMS_tasks_Initialize_user_tasks_p)();
231}
Note: See TracBrowser for help on using the repository browser.