RTEMS CPU Kit with SuperCore  4.11.2
userextimpl.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2009.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_SCORE_USEREXTIMPL_H
19 #define _RTEMS_SCORE_USEREXTIMPL_H
20 
21 #include <rtems/score/userext.h>
22 #include <rtems/score/chainimpl.h>
23 #include <rtems/score/percpu.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
42 
47 
53 void _User_extensions_Handler_initialization( void );
54 
55 void _User_extensions_Add_set(
56  User_extensions_Control *extension
57 );
58 
59 RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set(
60  User_extensions_Control *extension
61 )
62 {
63  _User_extensions_Add_set( extension );
64 }
65 
66 RTEMS_INLINE_ROUTINE void _User_extensions_Add_set_with_table(
67  User_extensions_Control *extension,
68  const User_extensions_Table *extension_table
69 )
70 {
71  extension->Callouts = *extension_table;
72 
73  _User_extensions_Add_set( extension );
74 }
75 
76 void _User_extensions_Remove_set(
77  User_extensions_Control *extension
78 );
79 
87 typedef void (*User_extensions_Visitor)(
88  Thread_Control *executing,
89  void *arg,
90  const User_extensions_Table *callouts
91 );
92 
93 typedef struct {
94  Thread_Control *created;
95  bool ok;
97 
98 void _User_extensions_Thread_create_visitor(
99  Thread_Control *executing,
100  void *arg,
101  const User_extensions_Table *callouts
102 );
103 
104 void _User_extensions_Thread_delete_visitor(
105  Thread_Control *executing,
106  void *arg,
107  const User_extensions_Table *callouts
108 );
109 
110 void _User_extensions_Thread_start_visitor(
111  Thread_Control *executing,
112  void *arg,
113  const User_extensions_Table *callouts
114 );
115 
116 void _User_extensions_Thread_restart_visitor(
117  Thread_Control *executing,
118  void *arg,
119  const User_extensions_Table *callouts
120 );
121 
122 void _User_extensions_Thread_begin_visitor(
123  Thread_Control *executing,
124  void *arg,
125  const User_extensions_Table *callouts
126 );
127 
128 void _User_extensions_Thread_exitted_visitor(
129  Thread_Control *executing,
130  void *arg,
131  const User_extensions_Table *callouts
132 );
133 
134 typedef struct {
135  Internal_errors_Source source;
136  bool is_internal;
137  Internal_errors_t error;
139 
140 void _User_extensions_Fatal_visitor(
141  Thread_Control *executing,
142  void *arg,
143  const User_extensions_Table *callouts
144 );
145 
146 void _User_extensions_Thread_terminate_visitor(
147  Thread_Control *executing,
148  void *arg,
149  const User_extensions_Table *callouts
150 );
151 
159  void *arg,
161 );
162 
170 static inline bool _User_extensions_Thread_create( Thread_Control *created )
171 {
172  User_extensions_Thread_create_context ctx = { created, true };
173 
174  _User_extensions_Iterate( &ctx, _User_extensions_Thread_create_visitor );
175 
176  return ctx.ok;
177 }
178 
179 static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
180 {
182  deleted,
183  _User_extensions_Thread_delete_visitor
184  );
185 }
186 
187 static inline void _User_extensions_Thread_start( Thread_Control *started )
188 {
190  started,
191  _User_extensions_Thread_start_visitor
192  );
193 }
194 
195 static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
196 {
198  restarted,
199  _User_extensions_Thread_restart_visitor
200  );
201 }
202 
203 static inline void _User_extensions_Thread_begin( Thread_Control *executing )
204 {
206  executing,
207  _User_extensions_Thread_begin_visitor
208  );
209 }
210 
211 static inline void _User_extensions_Thread_switch(
212  Thread_Control *executing,
213  Thread_Control *heir
214 )
215 {
217  const Chain_Node *tail = _Chain_Immutable_tail( chain );
218  const Chain_Node *node = _Chain_Immutable_first( chain );
219 
220  if ( node != tail ) {
221  Per_CPU_Control *cpu_self = _Per_CPU_Get();
222 
223  _Per_CPU_Acquire( cpu_self );
224 
225  while ( node != tail ) {
226  const User_extensions_Switch_control *extension =
227  (const User_extensions_Switch_control *) node;
228 
229  (*extension->thread_switch)( executing, heir );
230 
231  node = _Chain_Immutable_next( node );
232  }
233 
234  _Per_CPU_Release( cpu_self );
235  }
236 }
237 
238 static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
239 {
241  executing,
242  _User_extensions_Thread_exitted_visitor
243  );
244 }
245 
246 static inline void _User_extensions_Fatal(
247  Internal_errors_Source source,
248  bool is_internal,
249  Internal_errors_t error
250 )
251 {
252  User_extensions_Fatal_context ctx = { source, is_internal, error };
253 
254  _User_extensions_Iterate( &ctx, _User_extensions_Fatal_visitor );
255 }
256 
257 static inline void _User_extensions_Thread_terminate(
258  Thread_Control *executing
259 )
260 {
262  executing,
263  _User_extensions_Thread_terminate_visitor
264  );
265 }
266 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif
276 /* end of include file */
Manages the switch callouts.
Definition: userext.h:249
Definition: userextimpl.h:134
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
Chain_Control _User_extensions_List
List of active extensions.
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
Chain_Control _User_extensions_Switches_list
List of active task switch extensions.
This is used to manage a chain.
Definition: chain.h:83
void(* User_extensions_Visitor)(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
User extension visitor.
Definition: userextimpl.h:87
This include file defines the per CPU information required by RTEMS.
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
Per CPU Core Structure.
Definition: percpu.h:233
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_first(const Chain_Control *the_chain)
Return pointer to immutable chain&#39;s first node.
Definition: chainimpl.h:383
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_next(const Chain_Node *the_node)
Return pointer the immutable next node from this node.
Definition: chainimpl.h:449
Chain Handler API.
Definition: userextimpl.h:93
void _User_extensions_Iterate(void *arg, User_extensions_Visitor visitor)
Iterates through all user extensions and calls the visitor for each.
Definition: userextiterate.c:141
User extension table.
Definition: userext.h:232
Manages each user extension set.
Definition: userext.h:260
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_tail(const Chain_Control *the_chain)
Return pointer to immutable chain tail.
Definition: chainimpl.h:349
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:45
User Extension Handler API.