RTEMS  5.0.0
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 
22 #include <rtems/score/chainimpl.h>
23 #include <rtems/score/isrlock.h>
24 #include <rtems/score/thread.h>
25 #include <rtems/score/percpu.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
45 typedef struct User_extensions_Iterator {
46  Chain_Iterator Iterator;
47  struct User_extensions_Iterator *previous;
49 
50 typedef struct {
55 
60 
65  ISR_LOCK_MEMBER( Lock )
67 
72 
77 
83 void _User_extensions_Handler_initialization( void );
84 
85 void _User_extensions_Add_set(
86  User_extensions_Control *extension
87 );
88 
89 RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set(
90  User_extensions_Control *extension
91 )
92 {
93  _User_extensions_Add_set( extension );
94 }
95 
96 RTEMS_INLINE_ROUTINE void _User_extensions_Add_set_with_table(
97  User_extensions_Control *extension,
98  const User_extensions_Table *extension_table
99 )
100 {
101  extension->Callouts = *extension_table;
102 
103  _User_extensions_Add_set( extension );
104 }
105 
106 void _User_extensions_Remove_set(
107  User_extensions_Control *extension
108 );
109 
117 typedef void (*User_extensions_Visitor)(
118  Thread_Control *executing,
119  void *arg,
120  const User_extensions_Table *callouts
121 );
122 
123 typedef struct {
124  Thread_Control *created;
125  bool ok;
127 
128 void _User_extensions_Thread_create_visitor(
129  Thread_Control *executing,
130  void *arg,
131  const User_extensions_Table *callouts
132 );
133 
134 void _User_extensions_Thread_delete_visitor(
135  Thread_Control *executing,
136  void *arg,
137  const User_extensions_Table *callouts
138 );
139 
140 void _User_extensions_Thread_start_visitor(
141  Thread_Control *executing,
142  void *arg,
143  const User_extensions_Table *callouts
144 );
145 
146 void _User_extensions_Thread_restart_visitor(
147  Thread_Control *executing,
148  void *arg,
149  const User_extensions_Table *callouts
150 );
151 
152 void _User_extensions_Thread_begin_visitor(
153  Thread_Control *executing,
154  void *arg,
155  const User_extensions_Table *callouts
156 );
157 
158 void _User_extensions_Thread_exitted_visitor(
159  Thread_Control *executing,
160  void *arg,
161  const User_extensions_Table *callouts
162 );
163 
164 typedef struct {
165  Internal_errors_Source source;
166  Internal_errors_t error;
168 
169 void _User_extensions_Fatal_visitor(
170  Thread_Control *executing,
171  void *arg,
172  const User_extensions_Table *callouts
173 );
174 
175 void _User_extensions_Thread_terminate_visitor(
176  Thread_Control *executing,
177  void *arg,
178  const User_extensions_Table *callouts
179 );
180 
189  void *arg,
190  User_extensions_Visitor visitor,
191  Chain_Iterator_direction direction
192 );
193 
201 static inline bool _User_extensions_Thread_create( Thread_Control *created )
202 {
203  User_extensions_Thread_create_context ctx = { created, true };
204 
206  &ctx,
207  _User_extensions_Thread_create_visitor,
209  );
210 
211  return ctx.ok;
212 }
213 
214 static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
215 {
217  deleted,
218  _User_extensions_Thread_delete_visitor,
220  );
221 }
222 
223 static inline void _User_extensions_Thread_start( Thread_Control *started )
224 {
226  started,
227  _User_extensions_Thread_start_visitor,
229  );
230 }
231 
232 static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
233 {
235  restarted,
236  _User_extensions_Thread_restart_visitor,
238  );
239 }
240 
241 static inline void _User_extensions_Thread_begin( Thread_Control *executing )
242 {
244  executing,
245  _User_extensions_Thread_begin_visitor,
247  );
248 }
249 
250 static inline void _User_extensions_Thread_switch(
251  Thread_Control *executing,
252  Thread_Control *heir
253 )
254 {
255  const Chain_Control *chain;
256  const Chain_Node *tail;
257  const Chain_Node *node;
258 
260  tail = _Chain_Immutable_tail( chain );
261  node = _Chain_Immutable_first( chain );
262 
263  if ( node != tail ) {
264  Per_CPU_Control *cpu_self;
265 #if defined(RTEMS_SMP)
266  ISR_Level level;
267 #endif
268 
269  cpu_self = _Per_CPU_Get();
270 
271 #if defined(RTEMS_SMP)
272  _ISR_Local_disable( level );
273 #endif
274  _Per_CPU_Acquire( cpu_self );
275 
276 #if defined(RTEMS_SMP)
277  node = _Chain_Immutable_first( chain );
278 #endif
279 
280  while ( node != tail ) {
281  const User_extensions_Switch_control *extension =
282  (const User_extensions_Switch_control *) node;
283 
284  (*extension->thread_switch)( executing, heir );
285 
286  node = _Chain_Immutable_next( node );
287  }
288 
289  _Per_CPU_Release( cpu_self );
290 #if defined(RTEMS_SMP)
291  _ISR_Local_enable( level );
292 #endif
293  }
294 }
295 
296 static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
297 {
299  executing,
300  _User_extensions_Thread_exitted_visitor,
302  );
303 }
304 
305 static inline void _User_extensions_Fatal(
306  Internal_errors_Source source,
307  Internal_errors_t error
308 )
309 {
310  User_extensions_Fatal_context ctx = { source, error };
311 
313  &ctx,
314  _User_extensions_Fatal_visitor,
316  );
317 }
318 
319 static inline void _User_extensions_Thread_terminate(
320  Thread_Control *executing
321 )
322 {
324  executing,
325  _User_extensions_Thread_terminate_visitor,
327  );
328 }
329 
330 static inline void _User_extensions_Acquire( ISR_lock_Context *lock_context )
331 {
333  &_User_extensions_List.Lock,
334  lock_context
335  );
336 }
337 
338 static inline void _User_extensions_Release( ISR_lock_Context *lock_context )
339 {
341  &_User_extensions_List.Lock,
342  lock_context
343  );
344 }
345 
346 static inline void _User_extensions_Destroy_iterators(
347  Thread_Control *the_thread
348 )
349 {
350  ISR_lock_Context lock_context;
352 
353  _User_extensions_Acquire( &lock_context );
354 
355  iter = the_thread->last_user_extensions_iterator;
356 
357  while ( iter != NULL ) {
358  _Chain_Iterator_destroy( &iter->Iterator );
359  iter = iter->previous;
360  }
361 
362  _User_extensions_Release( &lock_context );
363 }
364 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif
374 /* end of include file */
Manages the switch callouts.
Definition: userextdata.h:39
Definition: userextimpl.h:164
Definition: chain.h:65
User Extension Handler Data Structures.
A chain iterator which is updated during node extraction if it is properly registered.
Definition: chainimpl.h:898
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:223
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
void _User_extensions_Iterate(void *arg, User_extensions_Visitor visitor, Chain_Iterator_direction direction)
Iterates through all user extensions and calls the visitor for each.
Definition: userextiterate.c:150
RTEMS_INLINE_ROUTINE void _Chain_Iterator_destroy(Chain_Iterator *the_iterator)
Destroys the iterator.
Definition: chainimpl.h:1110
#define ISR_LOCK_MEMBER(_designator)
Defines an ISR lock member.
Definition: isrlock.h:89
Chain_Control _User_extensions_Switches_list
List of active task switch extensions.
Definition: chain.h:83
Chain iterator for dynamic user extensions.
Definition: userextimpl.h:45
void(* User_extensions_Visitor)(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
User extension visitor.
Definition: userextimpl.h:117
struct User_extensions_Iterator * last_user_extensions_iterator
LIFO list of user extensions iterators.
Definition: thread.h:867
#define _ISR_Local_disable(_level)
Disables interrupts on this processor.
Definition: isrlevel.h:54
uint32_t ISR_Level
Definition: isrlevel.h:38
Definition: thread.h:728
Per CPU Core Structure.
Definition: percpu.h:290
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:248
Iteration from head to tail.
Definition: chainimpl.h:884
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:71
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:274
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:340
Definition: userextimpl.h:50
Chain Handler API.
Definition: userextimpl.h:123
User extension table.
Definition: userext.h:232
Chain_Iterator_registry Iterators
Chain iterator registration.
Definition: userextimpl.h:59
Manages each user extension set.
Definition: userextdata.h:50
Chain_Control Active
Active dynamically added user extensions.
Definition: userextimpl.h:54
Chain_Iterator_direction
The chain iterator direction.
Definition: chainimpl.h:880
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Iteration from tail to head.
Definition: chainimpl.h:889
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_tail(const Chain_Control *the_chain)
Return pointer to immutable chain tail.
Definition: chainimpl.h:240
User_extensions_List _User_extensions_List
List of active extensions.
Definition: userextiterate.c:32
Constants and Structures Related with the Thread Control Block.
ISR Locks.
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:42
struct User_extensions_Iterator User_extensions_Iterator
Chain iterator for dynamic user extensions.
A registry for chain iterators.
Definition: chainimpl.h:930
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77